This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package timex
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRelativeTime(t *testing.T) {
|
||||
time.Sleep(time.Millisecond)
|
||||
now := Now()
|
||||
assert.True(t, now > 0)
|
||||
time.Sleep(time.Millisecond)
|
||||
assert.True(t, Since(now) > 0)
|
||||
}
|
||||
|
||||
func BenchmarkTimeSince(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = time.Since(time.Now())
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTimexSince(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = Since(Now())
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package timex
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReprOfDuration(t *testing.T) {
|
||||
assert.Equal(t, "1000.0ms", ReprOfDuration(time.Second))
|
||||
assert.Equal(t, "1111.6ms", ReprOfDuration(
|
||||
time.Second+time.Millisecond*111+time.Microsecond*555))
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
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 range 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))
|
||||
}
|
||||
|
||||
func TestFakeTickerTimeout(t *testing.T) {
|
||||
ticker := NewFakeTicker()
|
||||
defer ticker.Stop()
|
||||
|
||||
assert.NotNil(t, ticker.Wait(time.Millisecond))
|
||||
}
|
||||
Reference in New Issue
Block a user