Skip to content

netsync: avoid clock tick race in sync state test#2564

Open
starius wants to merge 1 commit into
btcsuite:masterfrom
starius:fix-flaky-netstat-test
Open

netsync: avoid clock tick race in sync state test#2564
starius wants to merge 1 commit into
btcsuite:masterfrom
starius:fix-flaky-netstat-test

Conversation

@starius

@starius starius commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Change Description

TestSyncStateMachine checked that handleHeadersMsg advanced lastProgressTime by comparing it against the timestamp written by startSync. Those two writes can happen within the same clock tick, so the handler can update the field while time.After still reports false.

Reset lastProgressTime to the zero value before delivering headers and assert that the handler writes a non-zero value. This keeps the test focused on the behavior under test without depending on adjacent time.Now calls producing distinct timestamps.

Steps to Test

go test ./netsync -run TestSyncStateMachine -count=50

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

TestSyncStateMachine checked that handleHeadersMsg advanced
lastProgressTime by comparing it against the timestamp written by
startSync. Those two writes can happen within the same clock tick, so
the handler can update the field while time.After still reports false.

Reset lastProgressTime to the zero value before delivering headers and
assert that the handler writes a non-zero value. This keeps the test
focused on the behavior under test without depending on adjacent
time.Now calls producing distinct timestamps.
@allocz

allocz commented Jul 2, 2026

Copy link
Copy Markdown

I could not trigger the tick race here, but depending of the processor speed I agree that it may happen, so I'll give an ACK.

@TechLateef TechLateef left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good fix!

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.

3 participants