github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/common/stats_test.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package common
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestSampleIIIBasic(t *testing.T) {
    25  	r := NewSampleIII[int32](time.Millisecond*5, 3, 6)
    26  	for i := 0; i < 40; i++ {
    27  		time.Sleep(5 * time.Millisecond)
    28  		x := int32(500 * i)
    29  		r.Append(x)
    30  	}
    31  
    32  	short, mid, long := r.QueryTrend()
    33  	t.Logf("%+v, %v, %v, %v", r, short, mid, long)
    34  	require.True(t, long > TrendStable, long)
    35  	require.True(t, mid > TrendStable, mid)
    36  	require.True(t, short > TrendStable, short)
    37  
    38  	for i := 0; i < 60; i++ {
    39  		time.Sleep(5 * time.Millisecond)
    40  		r.Append(42)
    41  	}
    42  
    43  	short, mid, long = r.QueryTrend()
    44  	t.Logf("%+v, %v, %v, %v", r, short, mid, long)
    45  	require.Equal(t, TrendStable, short)
    46  	require.Equal(t, TrendStable, mid)
    47  	require.True(t, TrendIncI >= long)
    48  	require.True(t, TrendDecI <= long)
    49  
    50  	for i := 0; i < 60; i++ {
    51  		time.Sleep(5 * time.Millisecond)
    52  		r.Append(int32(-500 * i))
    53  	}
    54  
    55  	short, mid, long = r.QueryTrend()
    56  	t.Logf("%+v, %v, %v, %v", r, short, mid, long)
    57  	require.True(t, long < TrendStable, long)
    58  	require.True(t, mid < TrendStable, mid)
    59  	require.True(t, short < TrendStable, short)
    60  }