discovery/sync_manager_test: add TestSyncManagerHistoricalSyncOnReconnect

TestSyncManagerHistoricalSyncOnReconnect tests that the sync manager will
re-trigger a historical sync when a new peer connects after a historical
sync has completed, but we have lost all peers.
This commit is contained in:
Johan T. Halseth 2019-05-21 15:30:32 +02:00
parent 526486ae24
commit 6ba6982ae7
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -219,6 +219,41 @@ func TestSyncManagerInitialHistoricalSync(t *testing.T) {
assertNoMsgSent(t, extraPeer) assertNoMsgSent(t, extraPeer)
} }
// TestSyncManagerHistoricalSyncOnReconnect tests that the sync manager will
// re-trigger a historical sync when a new peer connects after a historical
// sync has completed, but we have lost all peers.
func TestSyncManagerHistoricalSyncOnReconnect(t *testing.T) {
t.Parallel()
syncMgr := newTestSyncManager(2)
syncMgr.Start()
defer syncMgr.Stop()
// We should expect to see a QueryChannelRange message with a
// FirstBlockHeight of the genesis block, signaling that an initial
// historical sync is being attempted.
peer := randPeer(t, syncMgr.quit)
syncMgr.InitSyncState(peer)
s := assertSyncerExistence(t, syncMgr, peer)
assertTransitionToChansSynced(t, s, peer)
assertActiveGossipTimestampRange(t, peer)
assertSyncerStatus(t, s, chansSynced, ActiveSync)
// Now that the historical sync is completed, we prune the syncer,
// simulating all peers having disconnected.
syncMgr.PruneSyncState(peer.PubKey())
// If a new peer now connects, then another historical sync should
// be attempted. This is to ensure we get an up-to-date graph if we
// haven't had any peers for a time.
nextPeer := randPeer(t, syncMgr.quit)
syncMgr.InitSyncState(nextPeer)
s1 := assertSyncerExistence(t, syncMgr, nextPeer)
assertTransitionToChansSynced(t, s1, nextPeer)
assertActiveGossipTimestampRange(t, nextPeer)
assertSyncerStatus(t, s1, chansSynced, ActiveSync)
}
// TestSyncManagerForceHistoricalSync ensures that we can perform routine // TestSyncManagerForceHistoricalSync ensures that we can perform routine
// historical syncs whenever the HistoricalSyncTicker fires. // historical syncs whenever the HistoricalSyncTicker fires.
func TestSyncManagerForceHistoricalSync(t *testing.T) { func TestSyncManagerForceHistoricalSync(t *testing.T) {