The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/internal/utils/timer_test.go

31 lines
621 B

package utils
import (
"testing"
"time"
)
func TestNewTimeout(t *testing.T) {
timer := NewTimeout(time.Second)
if timer == nil || timer.Duration() != time.Second || timer.IsActive() {
t.Fatalf("timer initialization error")
}
}
func TestCheckExpire(t *testing.T) {
timer := NewTimeout(time.Second)
timer.Start()
time.Sleep(2 * time.Second)
if timer.CheckExpire() == false {
t.Fatalf("CheckExpire should be true")
}
timer.Start()
if timer.CheckExpire() == true {
t.Fatalf("CheckExpire should be false")
}
timer.Stop()
if timer.CheckExpire() == true {
t.Fatalf("CheckExpire should be false")
}
}