Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unit tests for Block Synchronization Mechanism - Closes #4375 #4476

Merged
merged 20 commits into from Nov 11, 2019

Conversation

2snEM6
Copy link
Contributor

@2snEM6 2snEM6 commented Nov 6, 2019

What was the problem?

There were no unit tests for Block Synchronization Mechanism

How did I solve it?

By adding tests

How to manually test it?

Run block_synchronization_mechanism.spec.js with Jest

Review checklist

@2snEM6 2snEM6 self-assigned this Nov 6, 2019
@2snEM6 2snEM6 force-pushed the fcs_unit_tests branch 2 times, most recently from 49721e1 to c77a977 Compare November 6, 2019 15:00
@2snEM6 2snEM6 force-pushed the bsm_unit_tests branch 2 times, most recently from d08f368 to 931e4fa Compare November 7, 2019 08:41
@shuse2 shuse2 changed the title Implement unit tests for Block Synchronization Mechanism Implement unit tests for Block Synchronization Mechanism - Closes #4375 Nov 7, 2019
@2snEM6 2snEM6 force-pushed the fcs_unit_tests branch 3 times, most recently from ac3ff3e to 61adee1 Compare November 7, 2019 14:49
@shuse2 shuse2 changed the base branch from fcs_unit_tests to development November 7, 2019 15:49
@2snEM6 2snEM6 marked this pull request as ready for review November 7, 2019 16:34
async _handleBlockProcessingError(lastCommonBlock, peerId) {
// If the list of blocks has not been fully applied
this.logger.debug('Failed to apply obtained blocks from peer');
const [tipBeforeApplying] = await this.storage.entities.TempBlock.get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tipBeforeApplying can be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, in that case I guess we should restart mechanism only? and cleanup temp table just in case?

Copy link
Member

@shuse2 shuse2 Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if it fails to get then it's already cleaned up?
but in that case, i think we can just restart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe temp table is full and there is an error accessing database, hmmm

Copy link
Contributor

@ManuGowda ManuGowda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add missing test for isValidFor
  • Implement the following missing behaviour
async _requestAndValidateLastBlock(peerId) {
		this.logger.debug({ peerId }, 'Requesting tip of the chain from peer');

		const { data } = await this.channel.invoke('network:requestFromPeer', {
			procedure: 'getLastBlock',
			peerId,
		});
  • Mock peer to return empty data and handle the scenario
  • Update the title should give up requesting the last common block after 3 tries, and then ban the peer and restart the mechanism

tipBeforeApplyingInstance, // Previous tip of the chain
);

const newTipHasPreference = forkStatus === FORK_STATUS_DIFFERENT_CHAIN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to use directly in if condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is easier to read and to understand what the condition means, especially because the FORK_STATUS_DIFFERENT_CHAIN is not the best name to represent that behavior and I didn't want to change it in this PR

Copy link
Contributor

@ManuGowda ManuGowda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Check delete last block called with backUP true when deleting from common block
  • Clone deep the requested block to test truncate

@shuse2 shuse2 merged commit 5921a50 into development Nov 11, 2019
@sridharmeganathan sridharmeganathan modified the milestone: Sprint 9 Nov 11, 2019
@shuse2 shuse2 deleted the bsm_unit_tests branch November 18, 2019 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover block synchronisation mechanism with unit/integration tests
4 participants