github.com/lingyao2333/mo-zero@v1.4.1/core/load/sheddingstat_test.go (about)

     1  package load
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestSheddingStat(t *testing.T) {
    11  	st := NewSheddingStat("any")
    12  	for i := 0; i < 3; i++ {
    13  		st.IncrementTotal()
    14  	}
    15  	for i := 0; i < 5; i++ {
    16  		st.IncrementPass()
    17  	}
    18  	for i := 0; i < 7; i++ {
    19  		st.IncrementDrop()
    20  	}
    21  	result := st.reset()
    22  	assert.Equal(t, int64(3), result.Total)
    23  	assert.Equal(t, int64(5), result.Pass)
    24  	assert.Equal(t, int64(7), result.Drop)
    25  }
    26  
    27  func TestLoopTrue(t *testing.T) {
    28  	ch := make(chan time.Time, 1)
    29  	ch <- time.Now()
    30  	close(ch)
    31  	st := new(SheddingStat)
    32  	logEnabled.Set(true)
    33  	st.loop(ch)
    34  }
    35  
    36  func TestLoopTrueAndDrop(t *testing.T) {
    37  	ch := make(chan time.Time, 1)
    38  	ch <- time.Now()
    39  	close(ch)
    40  	st := new(SheddingStat)
    41  	st.IncrementDrop()
    42  	logEnabled.Set(true)
    43  	st.loop(ch)
    44  }
    45  
    46  func TestLoopFalseAndDrop(t *testing.T) {
    47  	ch := make(chan time.Time, 1)
    48  	ch <- time.Now()
    49  	close(ch)
    50  	st := new(SheddingStat)
    51  	st.IncrementDrop()
    52  	logEnabled.Set(false)
    53  	st.loop(ch)
    54  }