@@ -128,20 +128,25 @@ func newApfServerWithSingleRequest(t *testing.T, decision mockDecision) *httptes
128
128
t .Errorf ("execute should not be invoked" )
129
129
}
130
130
// atomicReadOnlyExecuting can be either 0 or 1 as we test one request at a time.
131
- if decision != decisionSkipFilter && atomicReadOnlyExecuting != 1 {
132
- t .Errorf ("Wanted %d requests executing, got %d" , 1 , atomicReadOnlyExecuting )
131
+ currentValue := atomicReadOnlyExecuting .Load ()
132
+ if decision != decisionSkipFilter && currentValue != 1 {
133
+ t .Errorf ("Wanted %d requests executing, got %d" , 1 , currentValue )
133
134
}
134
135
}
136
+
135
137
postExecuteFunc := func () {}
136
138
// atomicReadOnlyWaiting can be either 0 or 1 as we test one request at a time.
137
139
postEnqueueFunc := func () {
138
- if atomicReadOnlyWaiting != 1 {
139
- t .Errorf ("Wanted %d requests in queue, got %d" , 1 , atomicReadOnlyWaiting )
140
+ currentValue := atomicReadOnlyWaiting .Load ()
141
+ if currentValue != 1 {
142
+ t .Errorf ("Wanted %d requests in queue, got %d" , 1 , currentValue )
140
143
}
141
144
}
145
+
142
146
postDequeueFunc := func () {
143
- if atomicReadOnlyWaiting != 0 {
144
- t .Errorf ("Wanted %d requests in queue, got %d" , 0 , atomicReadOnlyWaiting )
147
+ currentValue := atomicReadOnlyWaiting .Load ()
148
+ if currentValue != 0 {
149
+ t .Errorf ("Wanted %d requests in queue, got %d" , 0 , currentValue )
145
150
}
146
151
}
147
152
return newApfServerWithHooks (t , decision , onExecuteFunc , postExecuteFunc , postEnqueueFunc , postDequeueFunc )
@@ -185,8 +190,9 @@ func newApfHandlerWithFilter(t *testing.T, flowControlFilter utilflowcontrol.Int
185
190
// TODO: all test(s) using this filter must run
186
191
// serially to each other
187
192
defer func () {
188
- if atomicReadOnlyExecuting != 0 {
189
- t .Errorf ("Wanted %d requests executing, got %d" , 0 , atomicReadOnlyExecuting )
193
+ currentValue := atomicReadOnlyExecuting .Load ()
194
+ if currentValue != 0 {
195
+ t .Errorf ("Wanted %d requests executing, got %d" , 0 , currentValue )
190
196
}
191
197
}()
192
198
apfHandler .ServeHTTP (w , r )
@@ -280,8 +286,9 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
280
286
onExecuteFunc := func () {
281
287
preStartExecute .Done ()
282
288
preStartExecute .Wait ()
283
- if int (atomicReadOnlyExecuting ) != concurrentRequests {
284
- t .Errorf ("Wanted %d requests executing, got %d" , concurrentRequests , atomicReadOnlyExecuting )
289
+ currentValue := atomicReadOnlyExecuting .Load ()
290
+ if int (currentValue ) != concurrentRequests {
291
+ t .Errorf ("Wanted %d requests executing, got %d" , concurrentRequests , currentValue )
285
292
}
286
293
postStartExecute .Done ()
287
294
postStartExecute .Wait ()
@@ -290,9 +297,9 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
290
297
postEnqueueFunc := func () {
291
298
preEnqueue .Done ()
292
299
preEnqueue .Wait ()
293
- if int ( atomicReadOnlyWaiting ) != concurrentRequests {
294
- t . Errorf ( "Wanted %d requests in queue, got %d" , 1 , atomicReadOnlyWaiting )
295
-
300
+ currentValue := atomicReadOnlyWaiting . Load ()
301
+ if int ( currentValue ) != concurrentRequests {
302
+ t . Errorf ( "Wanted %d requests in queue, got %d" , concurrentRequests , currentValue )
296
303
}
297
304
postEnqueue .Done ()
298
305
postEnqueue .Wait ()
@@ -301,8 +308,9 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
301
308
postDequeueFunc := func () {
302
309
preDequeue .Done ()
303
310
preDequeue .Wait ()
304
- if atomicReadOnlyWaiting != 0 {
305
- t .Errorf ("Wanted %d requests in queue, got %d" , 0 , atomicReadOnlyWaiting )
311
+ currentValue := atomicReadOnlyWaiting .Load ()
312
+ if currentValue != 0 {
313
+ t .Errorf ("Wanted %d requests in queue, got %d" , 0 , currentValue )
306
314
}
307
315
postDequeue .Done ()
308
316
postDequeue .Wait ()
0 commit comments