add unittests and bug fix

This commit is contained in:
hdt3213
2021-05-05 20:51:53 +08:00
parent f1ab47bd83
commit 18d2cbb29b
30 changed files with 704 additions and 446 deletions

View File

@@ -0,0 +1,20 @@
package timewheel
import (
"testing"
"time"
)
func TestDelay(t *testing.T) {
ch := make(chan time.Time)
beginTime := time.Now()
Delay(time.Second, "", func() {
ch <- time.Now()
})
execAt := <-ch
delayDuration := execAt.Sub(beginTime)
// usually 1.0~2.0 s
if delayDuration < time.Second || delayDuration > 3*time.Second {
t.Error("wrong execute time")
}
}