Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Ibft Int. testing - Round Change #537

Merged
merged 9 commits into from
Jan 10, 2019
Merged

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Jan 10, 2019

Integration tests have been added to determine the IBFT components
response to the reception of RoundChange messages.

Through the course of creating these tests the following changes were
made to the RoundChangeManager:

  • Stores RoundChangeMessages in the order of arrival
  • Discards subsequent RoundChange messages from the same node,
    targetting a specific round.

PR description

Fixed Issue(s)

Integration tests have been added to determine the IBFT components
response to the reception of RoundChange messages.

Through the course of creating these tests the following changes were
made to the RoundChangeManager:
* Stores RoundChangeMessages in the order of arrival
* Discards subsequent RoundChange messages from the same node,
  targetting a specific round.
return CommitMessageData.fromMessageData(actual).decode().equals(expected);
actualMessage = CommitMessageData.fromMessageData(actual).decode();
break;
// final SignedData<CommitPayload> actualCommit =
Copy link
Contributor

Choose a reason for hiding this comment

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

Or these these comments are going to become deleted or uncommented?

Copy link
Contributor Author

@rain-on rain-on Jan 10, 2019

Choose a reason for hiding this comment

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

Removed - now do a recursive Field-by-field comparison.

default:
return false;
assertThat(true).isFalse(); // fail
Copy link
Contributor

Choose a reason for hiding this comment

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

How about replacing assertThat(true).isFalse(); // fail with something like fail("Unexpected IBFTv2 message type")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
assertThat(expectedPayload.equals(actualMessage.getPayload())).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

A more comprehensive equals (that doesn't rely on equals being implemented correctly) for assertThat(expectedPayload.equals(actualMessage.getPayload())).isTrue(); would be
assertThat(actualMessage.getPayload()).isEqualToComparingFieldByFieldRecursively(expectedPayload);

It may or may not be easier / nicer to read, probably depends on personal preferences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Believe it or not - I was in the process of changing to this.

@@ -48,7 +48,7 @@

// Store only 1 round change per round per validator
@VisibleForTesting
final Map<Address, SignedData<RoundChangePayload>> receivedMessages = Maps.newHashMap();
final Map<Address, SignedData<RoundChangePayload>> receivedMessages = Maps.newLinkedHashMap();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for using the LinkedHashMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To maintain insertion order - its not required - but it makes testing and debug a whole lot easier

}
assertThat(expectedPayload.equals(actualMessage.getPayload())).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nicer to use the isEquals instead using equals with isTrue i.e. assertThat(expectedPayload).isEqualTo(actualMessage.getPayload());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to fieldByFieldRecursively

Copy link
Contributor

Choose a reason for hiding this comment

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

that's ok. still prefer equals though, field comparison is a bit ugly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but is a really easy easy to see when tests fail and why - rather than using a debugger.

package tech.pegasys.pantheon.consensus.ibft.tests;

import static java.util.Optional.empty;
import static org.mockito.Mockito.mock;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: noticed these imports aren't used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}

@Test
public void messagesFromPreviousRoundAreDiscardedOnTransitionToFutureRound() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this test hasn't been implemented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}

@Test
public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice to have a similar test that if we have proposals but not quorum we get a prepare certificate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

}

@Test
public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAreReceived() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: isn't this really we have quorum prepare messages and a proposal. without the proposal there wouldn't be a prepared cert if I remember correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

targetRound,
Optional.of(
new PreparedCertificate(
roles
Copy link
Contributor

Choose a reason for hiding this comment

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

be create some small helper functions within the test for the prepare and proposal payload, think that would make this test a bit more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed - done.

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

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

LGTM

@rain-on rain-on merged commit 603a5f3 into PegaSysEng:master Jan 10, 2019
@rain-on rain-on deleted the int_test_rc branch January 16, 2019 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants