2014-01-09 08:37:01 +04:00
|
|
|
package timingwheel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTimingWheel(t *testing.T) {
|
|
|
|
w := NewTimingWheel(1*time.Second, 10)
|
|
|
|
|
2014-03-28 10:11:28 +04:00
|
|
|
println(time.Now().Unix())
|
2014-01-09 08:37:01 +04:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-w.After(1 * time.Second):
|
2014-03-28 10:11:28 +04:00
|
|
|
println(time.Now().Unix())
|
2014-01-09 08:37:01 +04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 10:11:28 +04:00
|
|
|
|
|
|
|
func TestTask(t *testing.T) {
|
|
|
|
w := NewTimingWheel(1*time.Second, 10)
|
|
|
|
|
|
|
|
r := make(chan struct{})
|
|
|
|
f := func() {
|
|
|
|
println("hello world")
|
|
|
|
r <- struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.AddTask(1*time.Second, f)
|
|
|
|
|
|
|
|
<-r
|
|
|
|
println("over")
|
|
|
|
}
|