netsync: avoid clock tick race in sync state test

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.
This commit is contained in:
Boris Nagaev 2026-07-02 01:11:55 -05:00
parent 6cfd7172ea
commit 0860e42dcf
No known key found for this signature in database

View file

@ -869,9 +869,10 @@ func syncSendHeaders(t *testing.T, sm *SyncManager,
t.Helper()
// Record the progress time set by startIBD so we can verify
// that handleHeadersMsg advances it.
progressBefore := sm.lastProgressTime
// Reset the progress time to a zero sentinel so the assertion below
// verifies that handleHeadersMsg writes it without depending on the
// system clock advancing between calls to time.Now.
sm.lastProgressTime = time.Time{}
headers := wire.NewMsgHeaders()
for _, block := range blocks {
@ -887,7 +888,7 @@ func syncSendHeaders(t *testing.T, sm *SyncManager,
_, bestHeaderHeight := sm.chain.BestHeader()
require.Equal(t, int32(totalBlocks), bestHeaderHeight)
require.True(t, sm.lastProgressTime.After(progressBefore),
require.False(t, sm.lastProgressTime.IsZero(),
"handleHeadersMsg should update lastProgressTime")
wantRequested := make(map[chainhash.Hash]struct{}, len(blocks))