-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fix race in TestIntraQueryCache_ClientError
and TestInterQueryCache_ClientError
#7280
Open
Juneezee
wants to merge
1
commit into
open-policy-agent:main
Choose a base branch
from
Juneezee:test/querycache-race
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Juneezee
force-pushed
the
test/querycache-race
branch
from
January 17, 2025 12:35
6f180af
to
f8e691a
Compare
Juneezee
commented
Jan 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧐 Looks like we have another flaky test https://github.com/open-policy-agent/opa/actions/runs/12829170916/job/35774782220?pr=7280#step:6:372
--- FAIL: TestCertPoolReloading (3.05s)
server_test.go:6095: server address: 127.0.0.1:36833
server_test.go:6151: server started
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6213: server still doesn't trust client cert
server_test.go:6203: server didn't accept client cert before deadline
…ryCache_ClientError` Observed in [1]: 2025/01/16 03:11:32 http: panic serving 127.0.0.1:38698: send on closed channel goroutine 1575 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1947 +0x10a panic({0x10dc6e0?, 0x16ea610?}) /usr/local/go/src/runtime/panic.go:785 +0x132 github.com/open-policy-agent/opa/v1/topdown.TestIntraQueryCache_ClientError.func1.1({0x16f2740, 0xc0001ec1c0}, 0xc0006ee140) /src/v1/topdown/http_test.go:3360 +0x4d net/http.HandlerFunc.ServeHTTP(0xc000ac3010, {0x16f2740, 0xc0001ec1c0}, 0xc0006ee140) /usr/local/go/src/net/http/server.go:2220 +0x48 net/http.serverHandler.ServeHTTP({0xc0010d6900?}, {0x16f2740, 0xc0001ec1c0}, 0xc0006ee140) /usr/local/go/src/net/http/server.go:3210 +0x2a2 net/http.(*conn).serve(0xc0012d6120, {0x16f39f0, 0xc000e35500}) /usr/local/go/src/net/http/server.go:2092 +0x12a5 created by net/http.(*Server).Serve in goroutine 1505 /usr/local/go/src/net/http/server.go:3360 +0x8ed --- FAIL: TestIntraQueryCache_ClientError (0.00s) --- FAIL: TestIntraQueryCache_ClientError/no_raised_errors (0.05s) http_test.go:3379: Expected exactly 1 call to HTTP server, got 0 --- FAIL: TestInterQueryCache_ClientError (0.00s) --- FAIL: TestInterQueryCache_ClientError/raised_errors (0.07s) http_test.go:3446: Expected exactly 1 call to HTTP server, got 0 and [2]: 2025/01/16 18:49:26 http: panic serving 127.0.0.1:55452: send on closed channel goroutine 1584 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1947 +0x10a panic({0x10dc6e0?, 0x16ea610?}) /usr/local/go/src/runtime/panic.go:785 +0x132 github.com/open-policy-agent/opa/v1/topdown.TestIntraQueryCache_ClientError.func1.1({0x16f2740, 0xc0001ac380}, 0xc0000268c0) /src/v1/topdown/http_test.go:3360 +0x4d net/http.HandlerFunc.ServeHTTP(0xc001312a10, {0x16f2740, 0xc0001ac380}, 0xc0000268c0) /usr/local/go/src/net/http/server.go:2220 +0x48 net/http.serverHandler.ServeHTTP({0xc00047eae0?}, {0x16f2740, 0xc0001ac380}, 0xc0000268c0) /usr/local/go/src/net/http/server.go:3210 +0x2a2 net/http.(*conn).serve(0xc000127830, {0x16f39f0, 0xc000a2dd70}) /usr/local/go/src/net/http/server.go:2092 +0x12a5 created by net/http.(*Server).Serve in goroutine 1597 /usr/local/go/src/net/http/server.go:3360 +0x8ed --- FAIL: TestIntraQueryCache_ClientError (0.00s) --- FAIL: TestIntraQueryCache_ClientError/no_raised_errors (0.04s) http_test.go:3379: Expected exactly 1 call to HTTP server, got 0 [1]: https://github.com/open-policy-agent/opa/actions/runs/12801275263/job/35690527578 [2]: https://github.com/open-policy-agent/opa/actions/runs/12801275263/job/35734323510 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Juneezee
force-pushed
the
test/querycache-race
branch
from
January 23, 2025 13:53
f8e691a
to
c64d53a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why the changes in this PR are needed?
A race condition was observed in the
TestIntraQueryCache_ClientError
andTestInterQueryCache_ClientError
tests.First Job Attempt
CI job link: https://github.com/open-policy-agent/opa/actions/runs/12801275263/job/35690527578
Second Job Attempt
CI job link: https://github.com/open-policy-agent/opa/actions/runs/12801275263/job/35734323510
Root Cause
opa/v1/topdown/http_test.go
Lines 3423 to 3439 in 8067014
The issue lies in the
default
case in theselect
statement of thegetAllRequests
function:opa/v1/topdown/http_test.go
Lines 3452 to 3467 in 8067014
The race condition occurs when
runTopDownTestCase
completes before thehttp.HandlerFunc
in the test server executes. This leaves thech chan *http.Request
channel empty, triggering thedefault
case to return an empty[]*http.Request
. Then, thedefer close(ch)
call closes the channel. When thehttp.HandlerFunc
finally executes and tries to send send to the already closed channel, it causes the panichttp: panic serving 127.0.0.1:55452: send on closed channel
.What are the changes in this PR?
This PR updates the
TestIntraQueryCache_ClientError
andTestInterQueryCache_ClientError
tests to usecontext.Context
for waiting. A timeout of 1 second ensures all HTTP requests are processed by the test server before proceeding.Notes to assist PR review:
Further comments: