Revert "apiserver: fix data race in apf tests in server/filters package"

This reverts commit dde23bb0b1.
This commit is contained in:
Kensei Nakada 2024-09-03 19:39:38 +09:00
parent 9fe3b84107
commit d267721205

View File

@ -26,7 +26,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -129,20 +128,20 @@ func newApfServerWithSingleRequest(t *testing.T, decision mockDecision) *httptes
t.Errorf("execute should not be invoked") t.Errorf("execute should not be invoked")
} }
// atomicReadOnlyExecuting can be either 0 or 1 as we test one request at a time. // atomicReadOnlyExecuting can be either 0 or 1 as we test one request at a time.
if want, got := int32(1), atomic.LoadInt32(&atomicReadOnlyExecuting); decision != decisionSkipFilter && want != got { if decision != decisionSkipFilter && atomicReadOnlyExecuting != 1 {
t.Errorf("Wanted %d requests executing, got %d", want, got) t.Errorf("Wanted %d requests executing, got %d", 1, atomicReadOnlyExecuting)
} }
} }
postExecuteFunc := func() {} postExecuteFunc := func() {}
// atomicReadOnlyWaiting can be either 0 or 1 as we test one request at a time. // atomicReadOnlyWaiting can be either 0 or 1 as we test one request at a time.
postEnqueueFunc := func() { postEnqueueFunc := func() {
if want, got := int32(1), atomic.LoadInt32(&atomicReadOnlyWaiting); want != got { if atomicReadOnlyWaiting != 1 {
t.Errorf("Wanted %d requests in queue, got %d", want, got) t.Errorf("Wanted %d requests in queue, got %d", 1, atomicReadOnlyWaiting)
} }
} }
postDequeueFunc := func() { postDequeueFunc := func() {
if want, got := int32(0), atomic.LoadInt32(&atomicReadOnlyWaiting); want != got { if atomicReadOnlyWaiting != 0 {
t.Errorf("Wanted %d requests in queue, got %d", want, got) t.Errorf("Wanted %d requests in queue, got %d", 0, atomicReadOnlyWaiting)
} }
} }
return newApfServerWithHooks(t, decision, onExecuteFunc, postExecuteFunc, postEnqueueFunc, postDequeueFunc) return newApfServerWithHooks(t, decision, onExecuteFunc, postExecuteFunc, postEnqueueFunc, postDequeueFunc)
@ -180,8 +179,8 @@ func newApfHandlerWithFilter(t *testing.T, flowControlFilter utilflowcontrol.Int
})) }))
apfHandler.ServeHTTP(w, r) apfHandler.ServeHTTP(w, r)
postExecute() postExecute()
if want, got := int32(0), atomic.LoadInt32(&atomicReadOnlyExecuting); want != got { if atomicReadOnlyExecuting != 0 {
t.Errorf("Wanted %d requests executing, got %d", want, got) t.Errorf("Wanted %d requests executing, got %d", 0, atomicReadOnlyExecuting)
} }
}), requestInfoFactory) }), requestInfoFactory)
@ -271,8 +270,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
onExecuteFunc := func() { onExecuteFunc := func() {
preStartExecute.Done() preStartExecute.Done()
preStartExecute.Wait() preStartExecute.Wait()
if want, got := int32(concurrentRequests), atomic.LoadInt32(&atomicReadOnlyExecuting); want != got { if int(atomicReadOnlyExecuting) != concurrentRequests {
t.Errorf("Wanted %d requests executing, got %d", want, got) t.Errorf("Wanted %d requests executing, got %d", concurrentRequests, atomicReadOnlyExecuting)
} }
postStartExecute.Done() postStartExecute.Done()
postStartExecute.Wait() postStartExecute.Wait()
@ -281,8 +280,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
postEnqueueFunc := func() { postEnqueueFunc := func() {
preEnqueue.Done() preEnqueue.Done()
preEnqueue.Wait() preEnqueue.Wait()
if want, got := int32(concurrentRequests), atomic.LoadInt32(&atomicReadOnlyWaiting); want != got { if int(atomicReadOnlyWaiting) != concurrentRequests {
t.Errorf("Wanted %d requests in queue, got %d", want, got) t.Errorf("Wanted %d requests in queue, got %d", 1, atomicReadOnlyWaiting)
} }
postEnqueue.Done() postEnqueue.Done()
@ -292,8 +291,8 @@ func TestApfExecuteMultipleRequests(t *testing.T) {
postDequeueFunc := func() { postDequeueFunc := func() {
preDequeue.Done() preDequeue.Done()
preDequeue.Wait() preDequeue.Wait()
if want, got := int32(0), atomic.LoadInt32(&atomicReadOnlyWaiting); want != got { if atomicReadOnlyWaiting != 0 {
t.Errorf("Wanted %d requests in queue, got %d", want, got) t.Errorf("Wanted %d requests in queue, got %d", 0, atomicReadOnlyWaiting)
} }
postDequeue.Done() postDequeue.Done()
postDequeue.Wait() postDequeue.Wait()