From 04540d167623ec6d63f8b581facc0b84e84fff6e Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 19 Sep 2024 19:10:53 -0400 Subject: [PATCH] chore: fix `TestFullSyncIsFinished` --- dot/sync/fullsync.go | 14 ++++++-------- dot/sync/fullsync_test.go | 9 ++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dot/sync/fullsync.go b/dot/sync/fullsync.go index e5c75cf609..eb02990ec4 100644 --- a/dot/sync/fullsync.go +++ b/dot/sync/fullsync.go @@ -162,11 +162,10 @@ func (f *FullSyncStrategy) IsFinished(results []*syncTaskResult) (bool, []Change readyBlocks := make([][]*types.BlockData, 0, len(validResp)) for _, reqRespData := range validResp { - // if Gossamer requested the header, then the response data should - // contains the full blocks to be imported. - // if Gossamer didn't request the header, then the response should - // only contain the missing parts that will complete the unreadyBlocks - // and then with the blocks completed we should be able to import them + // if Gossamer requested the header, then the response data should contains + // the full blocks to be imported. If Gossamer didn't request the header, + // then the response should only contain the missing parts that will complete + // the unreadyBlocks and then with the blocks completed we should be able to import them if reqRespData.req.RequestField(messages.RequestedDataHeader) { updatedFragment, ok := f.unreadyBlocks.updateDisjointFragments(reqRespData.responseData) if ok { @@ -207,10 +206,9 @@ func (f *FullSyncStrategy) IsFinished(results []*syncTaskResult) (bool, []Change disjointFragments = append(disjointFragments, fragment) } - logger.Debugf("blocks to import: %d, disjoint fragments: %d", len(nextBlocksToImport), len(disjointFragments)) + fmt.Printf("blocks to import: %d, disjoint fragments: %d\n", len(nextBlocksToImport), len(disjointFragments)) - // this loop goal is to import ready blocks as well as - // update the highestFinalized header + // this loop goal is to import ready blocks as well as update the highestFinalized header for len(nextBlocksToImport) > 0 || len(disjointFragments) > 0 { for _, blockToImport := range nextBlocksToImport { imported, err := f.importer.handle(blockToImport, networkInitialSync) diff --git a/dot/sync/fullsync_test.go b/dot/sync/fullsync_test.go index a6ede033a3..72f73197ed 100644 --- a/dot/sync/fullsync_test.go +++ b/dot/sync/fullsync_test.go @@ -198,7 +198,7 @@ func TestFullSyncIsFinished(t *testing.T) { // 1 -> 10 { who: peer.ID("peerA"), - request: messages.NewBlockRequest(*variadic.Uint32OrHashFrom(1), 128, + request: messages.NewBlockRequest(*variadic.Uint32OrHashFrom(1), 127, messages.BootstrapRequestData, messages.Ascending), completed: true, response: fstTaskBlockResponse, @@ -208,7 +208,7 @@ func TestFullSyncIsFinished(t *testing.T) { // 129 -> 256 { who: peer.ID("peerA"), - request: messages.NewBlockRequest(*variadic.Uint32OrHashFrom(1), 128, + request: messages.NewBlockRequest(*variadic.Uint32OrHashFrom(129), 127, messages.BootstrapRequestData, messages.Ascending), completed: true, response: sndTaskBlockResponse, @@ -223,7 +223,7 @@ func TestFullSyncIsFinished(t *testing.T) { mockBlockState.EXPECT().GetHighestFinalisedHeader(). Return(genesisHeader, nil). - Times(3) + Times(4) mockBlockState.EXPECT(). HasHeader(fstTaskBlockResponse.BlockData[0].Header.ParentHash). @@ -252,9 +252,11 @@ func TestFullSyncIsFinished(t *testing.T) { require.NoError(t, err) require.False(t, done) + require.Equal(t, fs.requestQueue.Len(), 1) require.Len(t, fs.unreadyBlocks.incompleteBlocks, 0) require.Len(t, fs.unreadyBlocks.disjointFragments, 1) require.Equal(t, fs.unreadyBlocks.disjointFragments[0], sndTaskBlockResponse.BlockData) + require.Equal(t, len(fs.unreadyBlocks.disjointFragments[0]), len(sndTaskBlockResponse.BlockData)) expectedAncestorRequest := messages.NewBlockRequest( *variadic.Uint32OrHashFrom(sndTaskBlockResponse.BlockData[0].Header.ParentHash), @@ -285,6 +287,7 @@ func TestFullSyncIsFinished(t *testing.T) { require.NoError(t, err) require.False(t, done) + require.Equal(t, fs.requestQueue.Len(), 0) require.Len(t, fs.unreadyBlocks.incompleteBlocks, 0) require.Len(t, fs.unreadyBlocks.disjointFragments, 0) })