-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasyncwait_test.go
More file actions
48 lines (37 loc) · 808 Bytes
/
asyncwait_test.go
File metadata and controls
48 lines (37 loc) · 808 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
39
40
41
42
43
44
45
46
47
48
package asyncwait
import (
"testing"
"time"
)
func TestAsyncWait(t *testing.T) {
var enabled bool
go func() {
time.Sleep(50 * time.Millisecond)
enabled = true
}()
successful := NewAsyncWait(100, 20).Check(func() bool {
return enabled == true
})
if successful != true {
t.Errorf("failed to be successful")
}
if enabled != true {
t.Errorf("failed to test asyncwait, predicate was not true")
}
}
func TestAsyncWaitFail(t *testing.T) {
var enabled bool
go func() {
time.Sleep(150 * time.Millisecond)
enabled = true
}()
successful := NewAsyncWait(100, 20).Check(func() bool {
return enabled == true
})
if successful != false {
t.Errorf("should have failed")
}
if enabled != false {
t.Errorf("should have failed to test asyncwait, predicate should be false")
}
}