initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

46
core/timex/ticker_test.go Normal file
View File

@@ -0,0 +1,46 @@
package timex
import (
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRealTickerDoTick(t *testing.T) {
ticker := NewTicker(time.Millisecond * 10)
defer ticker.Stop()
var count int
for range ticker.Chan() {
count++
if count > 5 {
break
}
}
}
func TestFakeTicker(t *testing.T) {
const total = 5
ticker := NewFakeTicker()
defer ticker.Stop()
var count int32
go func() {
for {
select {
case <-ticker.Chan():
if atomic.AddInt32(&count, 1) == total {
ticker.Done()
}
}
}
}()
for i := 0; i < 5; i++ {
ticker.Tick()
}
assert.Nil(t, ticker.Wait(time.Second))
assert.Equal(t, int32(total), atomic.LoadInt32(&count))
}