github.com/anycable/anycable-go@v1.5.1/metrics/counter_test.go (about)

     1  package metrics
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCounter(t *testing.T) {
    10  	cnt := NewCounter("test", "")
    11  	assert.Equal(t, uint64(0), cnt.IntervalValue())
    12  	for i := 0; i < 1000; i++ {
    13  		cnt.Inc()
    14  	}
    15  	assert.Equal(t, uint64(1000), cnt.Value())
    16  	cnt.Add(500)
    17  	assert.Equal(t, uint64(1500), cnt.Value())
    18  	cnt.UpdateDelta()
    19  	cnt.Inc()
    20  	assert.Equal(t, uint64(1501), cnt.Value())
    21  	assert.Equal(t, uint64(1500), cnt.IntervalValue())
    22  	cnt.UpdateDelta()
    23  	assert.Equal(t, uint64(1501), cnt.Value())
    24  	assert.Equal(t, uint64(1), cnt.IntervalValue())
    25  	cnt.UpdateDelta()
    26  	assert.Equal(t, uint64(1501), cnt.Value())
    27  	assert.Equal(t, uint64(0), cnt.IntervalValue())
    28  }