-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_eventually_internal_test.go
More file actions
62 lines (47 loc) · 1.36 KB
/
Copy pathassert_eventually_internal_test.go
File metadata and controls
62 lines (47 loc) · 1.36 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package testastic
import (
"sync/atomic"
"testing"
"time"
)
func TestRunEventuallyCheck_DoesNotStartAfterDeadline(t *testing.T) {
t.Parallel()
// given: an Eventually check whose deadline has already passed
var calls atomic.Int32
results := make(chan eventuallyCheckResult[bool], 1)
done := make(chan struct{})
check := &eventuallyCheckState{}
// when: the check worker tries to execute the callback
runEventuallyCheck(func() bool {
calls.Add(1)
return false
}, results, done, check, time.Now().Add(-time.Second))
// then: the callback does not run or produce a result
Equal(t, int32(0), calls.Load())
select {
case <-results:
t.Error("expired check produced a result")
default:
}
}
func TestRunEventuallyCheck_DoesNotStartAfterCancellation(t *testing.T) {
t.Parallel()
// given: an Eventually check canceled before its worker starts
var calls atomic.Int32
results := make(chan eventuallyCheckResult[bool], 1)
done := make(chan struct{})
check := &eventuallyCheckState{}
check.cancel()
// when: the canceled check worker tries to execute the callback
runEventuallyCheck(func() bool {
calls.Add(1)
return false
}, results, done, check, time.Now().Add(time.Hour))
// then: the callback does not run or produce a result
Equal(t, int32(0), calls.Load())
select {
case <-results:
t.Error("canceled check produced a result")
default:
}
}