Skip to content

[Peers] Testing: Simplify unit tests of the event handling code #697

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

Open
Tracked by #707
julianknutsen opened this issue Sep 16, 2020 · 0 comments
Open
Tracked by #707

Comments

@julianknutsen
Copy link

As a developer, I want to modify the event handling code in peers/ with the safety of unit tests and that have their dependencies minimized so that I have confidence in the changes and the features are easy to write.

Definition of Done:

  • Unit tests are refactored from peers/handler.rs to a new module responsible for the event handling
  • Unit tests do not require a full PeerManager/Transport (even test double versions)

Tech Discussion:
The current tests of this code include the full PeerManager which adds other dependent objects that aren’t really necessary for true unit tests. Instead, this behavior can be factored out into an event_handler module that just takes in an event and the required dependencies and verifies the correct state change.

This likely involves splitting out an interface for retrieving an initialized peer by node_id (InitializedPeerProvider?/PeerIterator?). The PeerHolder can implement this in the real code and tests can have a simple wrapper around a HashMap.

Most of the existing tests of this in handler.rs can be removed in favor of a few sanity tests to make sure any interface breakdowns are caught early.

End result will look something like this:

#[test]
Fn example_test() {
	// create dependencies:
	// channel handler spy, route handler stub, initialized node provider
	
	process_event(XYZ);

	// validate spys, stubs, and outbound queues of peers match the expected behavior
}
@julianknutsen julianknutsen mentioned this issue Sep 16, 2020
18 tasks
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

No branches or pull requests

1 participant