Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: race panic intest/go/postgres#1752

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
coadler wants to merge1 commit intomainfromcolin/fix-test-race
Closed

Conversation

coadler
Copy link
Contributor

@coadlercoadler commentedMay 25, 2022
edited
Loading

https://github.com/coder/coder/actions/runs/2359166491/attempts/1

The current race condition is caused by a call tot.Log at the same time a test is finishing. This PR changes the logger to be swapped out before tests exit, to avoid any logs that may race with a test finishing.

johnstcn reacted with hooray emojijohnstcn reacted with heart emoji
@coadlercoadler self-assigned thisMay 25, 2022
@coadlercoadler linked an issueMay 25, 2022 that may beclosed by this pull request
@coadlercoadler marked this pull request as ready for reviewMay 25, 2022 18:30
@dwahler
Copy link
Contributor

I think this change would reduce the probability of a race, but not completely eliminate it.

In the current version of the code, the goroutine that generates the log message is readingcoderd.options.Logger, then callingDebug() on it which eventually callst.Log(). MakingLogger an atomic reference and clearing it during cleanup doesn't fix this, because a concurrently running goroutine might read the value ofLogger before it's cleared, but then callt.Log() after the test exits.

Here's a minimal example that demonstrates the same issue. It succeeds on the playground, but fails if run with-race -count=100.

I think fixing this properly requires pushing the synchronization all the way toslogtest.testSink. Something like:

type testSink struct {    tb testing.TB    mutex sync.Mutex    testDone bool}

@coadler
Copy link
ContributorAuthor

I looked into doing something like that as my first option, but how would the test sink know when the test exits?

@coadler
Copy link
ContributorAuthor

Hmm, I guess maybe if the sink had its ownt.Cleanup that set the flag that would work?

@dwahler
Copy link
Contributor

Yeah, at first I was thinking we'd have to makeslogtest.Make return an extra function/object/something to provide a way for the test code to signal that it was done, but just having the sink register its own cleanup function is much more elegant.

@coadler
Copy link
ContributorAuthor

Closing in favor ofcoder/slog#146 and#1759

@coadlercoadler deleted the colin/fix-test-race branchMay 25, 2022 20:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kylecarbskylecarbsAwaiting requested review from kylecarbs

@dwahlerdwahlerAwaiting requested review from dwahler

Assignees

@coadlercoadler

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@coadler@dwahler

[8]ページ先頭

©2009-2025 Movatter.jp