Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@tomaka
Copy link
Contributor

@tomaka tomaka commented Jul 4, 2019

The TestNet struct in substrate-network allows simulating a network. It is used in the tests of the network, of Aura, of Babe, and of GrandPa.

At the moment, it uses the internals of the network crate (more specifically: Protocol) and simulates a network on top of that. This PR changes that so that it uses the API surface of the network crate, therefore including discovery, pinging, and all that the networking actually does.

In order to do so, it is now possible to put the network in "memory only" mode. In this mode, the node addresses are in the form /memory/N where N is a randomly-generated u64. Nodes "connect" to each other using channels.

In the process, I've made all the tests asynchronous. No background thread is being spawned anymore.

Since we no longer decide which node is connected to which, "disconnecting" is now done by destroying nodes altogether. Other than this detail, I have tried to not change anything in the logic of the tests.

This will make it possible to continue the internal refactoring of the network crate, as we can now move touch things that would break the tests before. I've already opened #2962 that should be merged on top of this PR.

@tomaka tomaka added the A0-please_review Pull request needs code review. label Jul 4, 2019
@tomaka tomaka requested review from andresilva and arkpar July 4, 2019 12:11
let mut net = GrandpaTestNet::new(TestApi::new(voters), 4);
net.peer(0).push_blocks(20, false);
net.sync();
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| Ok(net.poll_until_sync()))).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Would rather see . poll_until_sync' accept runtime parameter and calling block_oninternally, to avoid repeating all thepoll_fnugliness. A more genericpoll_until` that accepts a function would also be useful.

@arkpar
Copy link
Member

arkpar commented Jul 4, 2019

Looks good, except for a minor nitpick

Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

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

lgtm

@andresilva andresilva merged commit dd3cab9 into paritytech:master Jul 5, 2019
@andresilva andresilva added A8-looksgood and removed A0-please_review Pull request needs code review. labels Jul 5, 2019
@tomaka tomaka deleted the transport-config branch July 5, 2019 11:49
@tomaka tomaka mentioned this pull request Jul 7, 2019
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