From 0860e42dcf8ddf2e71e77dd53402f602a33295a6 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 2 Jul 2026 01:11:55 -0500 Subject: [PATCH] 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. --- netsync/manager_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/netsync/manager_test.go b/netsync/manager_test.go index 4d304fc712..1e40dd8263 100644 --- a/netsync/manager_test.go +++ b/netsync/manager_test.go @@ -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))