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

[Merged by Bors] - Fix flaky TestHare_ReconstructForward #6299

Closed
wants to merge 3 commits into from

Conversation

fasmat
Copy link
Member

@fasmat fasmat commented Aug 28, 2024

Motivation

Fix flaky test.

Closes #6293.

Description

The reason the test is flaky is because occasionally the first node sends a hare message before the other nodes have started processing the layer yet. I updated the code to check if the node that "receives" the message has already updated its state to start processing the layer of interest.

Test Plan

Before the change this would always result in a fail on my machine:

go test -race -count=100 -run ^TestHare_ReconstructForward$ github.com/spacemeshos/go-spacemesh/hare4

After the change the test seems to be more reliable.

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

@fasmat fasmat self-assigned this Aug 28, 2024
@fasmat fasmat force-pushed the fix-6293 branch 2 times, most recently from f8ccb11 to b90c11b Compare August 28, 2024 17:24
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.7%. Comparing base (5b44c29) to head (a131cb3).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #6299   +/-   ##
=======================================
  Coverage     81.7%   81.7%           
=======================================
  Files          312     312           
  Lines        34613   34613           
=======================================
+ Hits         28297   28300    +3     
+ Misses        4479    4477    -2     
+ Partials      1837    1836    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

hare3/hare_test.go Outdated Show resolved Hide resolved
Comment on lines 1211 to 1218
if !assert.Eventually(t, func() bool {
cluster.nodes[other[0]].hare.mu.Lock()
defer cluster.nodes[other[0]].hare.mu.Unlock()
_, registered := cluster.nodes[other[0]].hare.sessions[m.Layer]
return registered
}, 5*time.Second, 50*time.Millisecond) {
panic(fmt.Sprintf("node %d did not register in time", other[0]))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about

Suggested change
if !assert.Eventually(t, func() bool {
cluster.nodes[other[0]].hare.mu.Lock()
defer cluster.nodes[other[0]].hare.mu.Unlock()
_, registered := cluster.nodes[other[0]].hare.sessions[m.Layer]
return registered
}, 5*time.Second, 50*time.Millisecond) {
panic(fmt.Sprintf("node %d did not register in time", other[0]))
}
require.Eventuallyf(t, func() bool {
cluster.nodes[other[0]].hare.mu.Lock()
defer cluster.nodes[other[0]].hare.mu.Unlock()
_, registered := cluster.nodes[other[0]].hare.sessions[m.Layer]
return registered
}, 5*time.Second, 50*time.Millisecond, node %d did not register in time", other[0])

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason for the assert & panic is that if the assertion fails require calls t.Fail which marks the test as failing and stops the current go routine. This call to Publish however is not on the main go routine which is now stuck waiting for it to return.

Normally this can be implemented cleanly with gomock.WithContext and passing that context to the code that calls the mocks. I tried updating the code to make that work, but it turned out to be too big of a refactoring to fix a single flaky test.

Instead I cleaned up the code a bit and in the case a require fails we just rely on the calling side to time out correctly.

hare4/hare_test.go Outdated Show resolved Hide resolved
@fasmat
Copy link
Member Author

fasmat commented Aug 29, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Aug 29, 2024
## Motivation

Fix flaky test.

Closes #6293.
@fasmat
Copy link
Member Author

fasmat commented Aug 29, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Aug 29, 2024
## Motivation

Fix flaky test.

Closes #6293.
@spacemesh-bors
Copy link

Build failed:

  • systest-status

@fasmat
Copy link
Member Author

fasmat commented Aug 29, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Aug 29, 2024
## Motivation

Fix flaky test.

Closes #6293.
@spacemesh-bors
Copy link

Build failed (retrying...):

spacemesh-bors bot pushed a commit that referenced this pull request Aug 29, 2024
## Motivation

Fix flaky test.

Closes #6293.
@spacemesh-bors
Copy link

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title Fix flaky TestHare_ReconstructForward [Merged by Bors] - Fix flaky TestHare_ReconstructForward Aug 29, 2024
@spacemesh-bors spacemesh-bors bot closed this Aug 29, 2024
@spacemesh-bors spacemesh-bors bot deleted the fix-6293 branch August 29, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky TestHare_ReconstructForward
2 participants