2014-09-13 13:00:14 +04:00
|
|
|
package time2
|
2014-04-15 12:36:20 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2014-04-16 06:26:37 +04:00
|
|
|
var testWheel = NewWheel(1 * time.Millisecond)
|
2014-04-15 12:36:20 +04:00
|
|
|
|
|
|
|
func TestTimer(t *testing.T) {
|
|
|
|
t1 := testWheel.NewTimer(500 * time.Millisecond)
|
|
|
|
|
|
|
|
before := time.Now()
|
|
|
|
<-t1.C
|
|
|
|
|
|
|
|
after := time.Now()
|
|
|
|
|
|
|
|
println(after.Sub(before).String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTicker(t *testing.T) {
|
|
|
|
wait := make(chan struct{}, 100)
|
|
|
|
i := 0
|
|
|
|
f := func() {
|
|
|
|
println(time.Now().Unix())
|
|
|
|
i++
|
|
|
|
if i >= 10 {
|
|
|
|
wait <- struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
before := time.Now()
|
|
|
|
|
|
|
|
t1 := testWheel.TickFunc(1000*time.Millisecond, f)
|
|
|
|
|
|
|
|
<-wait
|
|
|
|
|
|
|
|
t1.Stop()
|
|
|
|
|
|
|
|
after := time.Now()
|
|
|
|
|
|
|
|
println(after.Sub(before).String())
|
|
|
|
}
|