@@ -26,6 +26,7 @@ import (
26
26
"reflect"
27
27
"strings"
28
28
"sync"
29
+ "sync/atomic"
29
30
"testing"
30
31
"time"
31
32
@@ -128,20 +129,20 @@ func newApfServerWithSingleRequest(t *testing.T, decision mockDecision) *httptes
128
129
t .Errorf ("execute should not be invoked" )
129
130
}
130
131
// 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 )
132
+ if want , got := int32 ( 1 ), atomic . LoadInt32 ( & atomicReadOnlyExecuting ); decision != decisionSkipFilter && want != got {
133
+ t .Errorf ("Wanted %d requests executing, got %d" , want , got )
133
134
}
134
135
}
135
136
postExecuteFunc := func () {}
136
137
// atomicReadOnlyWaiting can be either 0 or 1 as we test one request at a time.
137
138
postEnqueueFunc := func () {
138
- if atomicReadOnlyWaiting != 1 {
139
- t .Errorf ("Wanted %d requests in queue, got %d" , 1 , atomicReadOnlyWaiting )
139
+ if want , got := int32 ( 1 ), atomic . LoadInt32 ( & atomicReadOnlyWaiting ); want != got {
140
+ t .Errorf ("Wanted %d requests in queue, got %d" , want , got )
140
141
}
141
142
}
142
143
postDequeueFunc := func () {
143
- if atomicReadOnlyWaiting != 0 {
144
- t .Errorf ("Wanted %d requests in queue, got %d" , 0 , atomicReadOnlyWaiting )
144
+ if want , got := int32 ( 0 ), atomic . LoadInt32 ( & atomicReadOnlyWaiting ); want != got {
145
+ t .Errorf ("Wanted %d requests in queue, got %d" , want , got )
145
146
}
146
147
}
147
148
return newApfServerWithHooks (t , decision , onExecuteFunc , postExecuteFunc , postEnqueueFunc , postDequeueFunc )
@@ -179,8 +180,8 @@ func newApfHandlerWithFilter(t *testing.T, flowControlFilter utilflowcontrol.Int
179
180
}))
180
181
apfHandler .ServeHTTP (w , r )
181
182
postExecute ()
182
- if atomicReadOnlyExecuting != 0 {
183
- t .Errorf ("Wanted %d requests executing, got %d" , 0 , atomicReadOnlyExecuting )
183
+ if want , got := int32 ( 0 ), atomic . LoadInt32 ( & atomicReadOnlyExecuting ); want != got {
184
+ t .Errorf ("Wanted %d requests executing, got %d" , want , got )
184
185
}
185
186
}), requestInfoFactory )
186
187
@@ -270,8 +271,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
270
271
onExecuteFunc := func () {
271
272
preStartExecute .Done ()
272
273
preStartExecute .Wait ()
273
- if int ( atomicReadOnlyExecuting ) != concurrentRequests {
274
- t .Errorf ("Wanted %d requests executing, got %d" , concurrentRequests , atomicReadOnlyExecuting )
274
+ if want , got := int32 ( concurrentRequests ), atomic . LoadInt32 ( & atomicReadOnlyExecuting ); want != got {
275
+ t .Errorf ("Wanted %d requests executing, got %d" , want , got )
275
276
}
276
277
postStartExecute .Done ()
277
278
postStartExecute .Wait ()
@@ -280,8 +281,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
280
281
postEnqueueFunc := func () {
281
282
preEnqueue .Done ()
282
283
preEnqueue .Wait ()
283
- if int ( atomicReadOnlyWaiting ) != concurrentRequests {
284
- t .Errorf ("Wanted %d requests in queue, got %d" , 1 , atomicReadOnlyWaiting )
284
+ if want , got := int32 ( concurrentRequests ), atomic . LoadInt32 ( & atomicReadOnlyWaiting ); want != got {
285
+ t .Errorf ("Wanted %d requests in queue, got %d" , want , got )
285
286
286
287
}
287
288
postEnqueue .Done ()
@@ -291,8 +292,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
291
292
postDequeueFunc := func () {
292
293
preDequeue .Done ()
293
294
preDequeue .Wait ()
294
- if atomicReadOnlyWaiting != 0 {
295
- t .Errorf ("Wanted %d requests in queue, got %d" , 0 , atomicReadOnlyWaiting )
295
+ if want , got := int32 ( 0 ), atomic . LoadInt32 ( & atomicReadOnlyWaiting ); want != got {
296
+ t .Errorf ("Wanted %d requests in queue, got %d" , want , got )
296
297
}
297
298
postDequeue .Done ()
298
299
postDequeue .Wait ()
0 commit comments