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.
32 lines
621 B
32 lines
621 B
6 years ago
|
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")
|
||
|
}
|
||
|
|
||
|
}
|