Skip to content
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

Fix race condition in test #337

Merged
merged 2 commits into from
Oct 11, 2023
Merged

Fix race condition in test #337

merged 2 commits into from
Oct 11, 2023

Conversation

kegsay
Copy link
Member

@kegsay kegsay commented Oct 11, 2023

Implements half of #243 in a different way which involves less error prone locking.

@kegsay kegsay added bug Something isn't working flake Tests that fail intermittently; sporadic false positives labels Oct 11, 2023
@kegsay kegsay requested a review from DMRobertson October 11, 2023 11:37
@@ -31,29 +50,31 @@ func TestDeviceTickerBasic(t *testing.T) {
DeviceID: "b",
})
time.Sleep(duration * 2)
if len(payloads) != 1 {
t.Fatalf("expected 1 callback, got %d", len(payloads))
result := payloads.clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to clone here, sorry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to lock every time we access the underlying slice, which could then lead to inconsistent results (e.g len=1 when len() is called, but then increases to len=2 later on. It's easier to snapshot the slice.

@kegsay kegsay merged commit fe624d5 into main Oct 11, 2023
7 checks passed
Comment on lines +30 to +34
func setTimeSinceValue(val time.Duration) {
timeSinceMu.Lock()
timeSinceValue = time.Minute * 2
timeSinceMu.Unlock()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val seems unused here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flake Tests that fail intermittently; sporadic false positives
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants