mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-13 12:32:51 +02:00
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:
parent
6cfd7172ea
commit
0860e42dcf
1 changed files with 5 additions and 4 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue