Skip to content

Commit

Permalink
chore: fix TestFullSyncIsFinished
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Sep 19, 2024
1 parent b3e6bf4 commit 04540d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 6 additions & 8 deletions dot/sync/fullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions dot/sync/fullsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 04540d1

Please sign in to comment.