github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/etime/etime_interval_test.go (about)

     1  package etime
     2  
     3  import (
     4  	"github.com/go-eden/common/esync"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestInterval(t *testing.T) {
    11  	var counter esync.AtomicUint16
    12  	var it = NewInterval(time.Millisecond*100, func() {
    13  		counter.Inc()
    14  	})
    15  	time.Sleep(time.Second)
    16  
    17  	cv := counter.Get()
    18  	assert.True(t, cv == 10 || cv == 9, cv)
    19  	it.Close()
    20  	assert.True(t, counter.Get() == cv)
    21  }