mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-18 14:50:38 +08:00
add unittests and bug fix
This commit is contained in:
20
lib/timewheel/delay_test.go
Normal file
20
lib/timewheel/delay_test.go
Normal 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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user