-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasyncwait_test.go
More file actions
38 lines (34 loc) · 982 Bytes
/
Copy pathasyncwait_test.go
File metadata and controls
38 lines (34 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package asyncwait
import (
"testing"
"time"
)
// TestPositiveAsyncWait check positive scenario when TestFunc duration less than timeout
func TestPositiveAsyncWait(t *testing.T) {
ws, fs := testTemplate(20*time.Millisecond, 60*time.Millisecond, 20*time.Millisecond)
if !ws {
t.Errorf("AsyncWaitFunc is not true")
}
if !fs {
t.Errorf("TestFunc is not true")
}
}
// TestNegativeAsyncWait check negative scenario when TestFunc duration more than timeout
func TestNegativeAsyncWait(t *testing.T) {
ws, fs := testTemplate(80*time.Millisecond, 60*time.Millisecond, 20*time.Millisecond)
if ws {
t.Errorf("AsyncWaitFunc is not false")
}
if fs {
t.Errorf("TestFunc is not false")
}
}
func testTemplate(funcTimeout, timeout, pollInterval time.Duration) (waitStatus, funcStatus bool) {
funcStatus = false
go func() {
time.Sleep(funcTimeout)
funcStatus = true
}()
waitStatus = NewAsyncWait(timeout, pollInterval).Wait(func() bool { return funcStatus })
return
}