@@ -28,6 +28,7 @@ import (
28
28
)
29
29
30
30
func TestExecute (t * testing.T ) {
31
+ _ , ctx := ktesting .NewTestContext (t )
31
32
testVal := int32 (0 )
32
33
wg := sync.WaitGroup {}
33
34
wg .Add (5 )
@@ -37,17 +38,11 @@ func TestExecute(t *testing.T) {
37
38
return nil
38
39
})
39
40
now := time .Now ()
40
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , now )
41
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , now )
42
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , now )
43
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , now )
44
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , now )
45
- // Adding the same thing second time should be no-op
46
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , now )
47
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , now )
48
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , now )
49
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , now )
50
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , now )
41
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , now )
42
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , now )
43
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , now )
44
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , now )
45
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , now )
51
46
wg .Wait ()
52
47
lastVal := atomic .LoadInt32 (& testVal )
53
48
if lastVal != 5 {
@@ -56,6 +51,7 @@ func TestExecute(t *testing.T) {
56
51
}
57
52
58
53
func TestExecuteDelayed (t * testing.T ) {
54
+ _ , ctx := ktesting .NewTestContext (t )
59
55
testVal := int32 (0 )
60
56
wg := sync.WaitGroup {}
61
57
wg .Add (5 )
@@ -68,16 +64,16 @@ func TestExecuteDelayed(t *testing.T) {
68
64
then := now .Add (10 * time .Second )
69
65
fakeClock := testingclock .NewFakeClock (now )
70
66
queue .clock = fakeClock
71
- queue .AddWork (context . TODO () , NewWorkArgs ("1" , "1" ), now , then )
72
- queue .AddWork (context . TODO () , NewWorkArgs ("2" , "2" ), now , then )
73
- queue .AddWork (context . TODO () , NewWorkArgs ("3" , "3" ), now , then )
74
- queue .AddWork (context . TODO () , NewWorkArgs ("4" , "4" ), now , then )
75
- queue .AddWork (context . TODO () , NewWorkArgs ("5" , "5" ), now , then )
76
- queue .AddWork (context . TODO () , NewWorkArgs ("1" , "1" ), now , then )
77
- queue .AddWork (context . TODO () , NewWorkArgs ("2" , "2" ), now , then )
78
- queue .AddWork (context . TODO () , NewWorkArgs ("3" , "3" ), now , then )
79
- queue .AddWork (context . TODO () , NewWorkArgs ("4" , "4" ), now , then )
80
- queue .AddWork (context . TODO () , NewWorkArgs ("5" , "5" ), now , then )
67
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
68
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
69
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
70
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
71
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
72
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
73
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
74
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
75
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
76
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
81
77
fakeClock .Step (11 * time .Second )
82
78
wg .Wait ()
83
79
lastVal := atomic .LoadInt32 (& testVal )
@@ -87,6 +83,7 @@ func TestExecuteDelayed(t *testing.T) {
87
83
}
88
84
89
85
func TestCancel (t * testing.T ) {
86
+ logger , ctx := ktesting .NewTestContext (t )
90
87
testVal := int32 (0 )
91
88
wg := sync.WaitGroup {}
92
89
wg .Add (3 )
@@ -99,17 +96,16 @@ func TestCancel(t *testing.T) {
99
96
then := now .Add (10 * time .Second )
100
97
fakeClock := testingclock .NewFakeClock (now )
101
98
queue .clock = fakeClock
102
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , then )
103
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , then )
104
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , then )
105
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , then )
106
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , then )
107
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , then )
108
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , then )
109
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , then )
110
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , then )
111
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , then )
112
- logger , _ := ktesting .NewTestContext (t )
99
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
100
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
101
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
102
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
103
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
104
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
105
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
106
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
107
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
108
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
113
109
queue .CancelWork (logger , NewWorkArgs ("2" , "2" ).KeyFromWorkArgs ())
114
110
queue .CancelWork (logger , NewWorkArgs ("4" , "4" ).KeyFromWorkArgs ())
115
111
fakeClock .Step (11 * time .Second )
@@ -121,6 +117,7 @@ func TestCancel(t *testing.T) {
121
117
}
122
118
123
119
func TestCancelAndReadd (t * testing.T ) {
120
+ logger , ctx := ktesting .NewTestContext (t )
124
121
testVal := int32 (0 )
125
122
wg := sync.WaitGroup {}
126
123
wg .Add (4 )
@@ -133,20 +130,19 @@ func TestCancelAndReadd(t *testing.T) {
133
130
then := now .Add (10 * time .Second )
134
131
fakeClock := testingclock .NewFakeClock (now )
135
132
queue .clock = fakeClock
136
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , then )
137
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , then )
138
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , then )
139
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , then )
140
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , then )
141
- queue .AddWork (context .TODO (), NewWorkArgs ("1" , "1" ), now , then )
142
- queue .AddWork (context .TODO (), NewWorkArgs ("2" , "2" ), now , then )
143
- queue .AddWork (context .TODO (), NewWorkArgs ("3" , "3" ), now , then )
144
- queue .AddWork (context .TODO (), NewWorkArgs ("4" , "4" ), now , then )
145
- queue .AddWork (context .TODO (), NewWorkArgs ("5" , "5" ), now , then )
146
- logger , _ := ktesting .NewTestContext (t )
133
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
134
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
135
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
136
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
137
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
138
+ queue .AddWork (ctx , NewWorkArgs ("1" , "1" ), now , then )
139
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
140
+ queue .AddWork (ctx , NewWorkArgs ("3" , "3" ), now , then )
141
+ queue .AddWork (ctx , NewWorkArgs ("4" , "4" ), now , then )
142
+ queue .AddWork (ctx , NewWorkArgs ("5" , "5" ), now , then )
147
143
queue .CancelWork (logger , NewWorkArgs ("2" , "2" ).KeyFromWorkArgs ())
148
144
queue .CancelWork (logger , NewWorkArgs ("4" , "4" ).KeyFromWorkArgs ())
149
- queue .AddWork (context . TODO () , NewWorkArgs ("2" , "2" ), now , then )
145
+ queue .AddWork (ctx , NewWorkArgs ("2" , "2" ), now , then )
150
146
fakeClock .Step (11 * time .Second )
151
147
wg .Wait ()
152
148
lastVal := atomic .LoadInt32 (& testVal )
0 commit comments