anyhttp/idle/idle_test.go

35 lines
587 B
Go
Raw Permalink Normal View History

2023-05-08 22:37:03 -04:00
package idle
import (
"testing"
"time"
)
func TestIdlerChan(_ *testing.T) {
2023-09-11 20:44:52 -04:00
i := CreateIdler(10 * time.Millisecond)
2023-05-08 22:37:03 -04:00
<-i.Chan()
}
2023-09-11 20:44:52 -04:00
func TestGlobalIdler(t *testing.T) {
err := Wait(10 * time.Millisecond)
if err != nil {
t.Fatalf("idle.Wait failed, %v", err)
}
err = Wait(10 * time.Millisecond)
if err == nil {
t.Fatal("idle.Wait should fail when called second time")
}
}
func TestIdlerEnterExit(t *testing.T) {
i := CreateIdler(10 * time.Millisecond).(*idler)
i.Enter()
if i.active.Load() != 1 {
t.FailNow()
}
i.Exit()
if i.active.Load() != 0 {
t.FailNow()
}
}