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

p2p/simulations, swarm/network: Custom services in snapshot #17991

Merged
merged 9 commits into from
Nov 12, 2018

Conversation

nolash
Copy link
Contributor

@nolash nolash commented Oct 28, 2018

This PR makes it possible to selectively add and remove services from snapshot generated from simulations discovery test.

It also prunes connection objects that have status down from the generated snapshots.

Note; this uses sleeps for the TestSnapshotExplicit test because the timing of peer events and actual changes in state in the simulated nodes seems to be imprecise (and the test in itself is very simple). Fixing this will be a separate PR.

network.Connect(ids[0], ids[2])
time.Sleep(time.Second)
network.Disconnect(ids[0], ids[2])
time.Sleep(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried shorter Sleeps? The time.Second are adding up....Without wanting to add more complexity, what about listening to the Connection and Disconnection events?

p2p/simulations/network_test.go Outdated Show resolved Hide resolved
rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)")
initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)")
snapshotFile = flag.String("snapshot", "", "create snapshot")
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this better to document as "path of snapshot file created" or something like that?

Copy link
Member

Choose a reason for hiding this comment

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

done

p2p/simulations/network_test.go Outdated Show resolved Hide resolved
@nolash nolash requested a review from janos as a code owner November 7, 2018 08:10
@acud acud force-pushed the discovery-snapshot-customservice branch from 20dab68 to e59205c Compare November 7, 2018 08:16
p2p/simulations/network_test.go Outdated Show resolved Hide resolved
p2p/simulations/network_test.go Outdated Show resolved Hide resolved
}
}

snap, err = network.SnapshotWithServices([]string{"bzz"}, []string{"test"})
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it is best to put dummy2 in the services to be removed not the non-existing test and then check it it is removed on line 129

Copy link
Member

Choose a reason for hiding this comment

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

woops. done

adapter := adapters.NewSimAdapter(adapters.Services{
"dummy": newDummyService,
"dummy2": newDummy2Service,
"dummy": node.NewNoopServiceA,
Copy link
Contributor

Choose a reason for hiding this comment

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

nice one

Copy link
Contributor

Choose a reason for hiding this comment

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

adapter := adapters.NewSimAdapter(adapters.Services{
"dummy": newDummyService,
"dummy2": newDummy2Service,
"dummy": node.NewNoopServiceA,
Copy link
Contributor

Choose a reason for hiding this comment

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

p2p/simulations/network_test.go Outdated Show resolved Hide resolved
@nolash nolash requested a review from nonsense as a code owner November 8, 2018 13:56
@acud acud force-pushed the discovery-snapshot-customservice branch from 020fb88 to 5ec709a Compare November 8, 2018 14:15
Copy link
Contributor

@zelig zelig left a comment

Choose a reason for hiding this comment

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

LGTM now

@@ -676,6 +722,9 @@ func TestHTTPSnapshot(t *testing.T) {
if conn.Other.String() != nodes[1].ID {
t.Fatalf("expected connection to have other=%q, got other=%q", nodes[1].ID, conn.Other)
}
if conn.Up == false {
Copy link
Contributor

Choose a reason for hiding this comment

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

if !conn.Up

Copy link
Contributor

@janos janos left a comment

Choose a reason for hiding this comment

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

LGTM

Only one general suggestion. It would be good to signal done channels (in this case eventsDone) with closing them, rather then sending an empty struct to it, even if there is only one receiver. Adding new receivers would not require changing the sender part and code semantics would be right if someone uses it as an example or copies it.

@zelig zelig merged commit 201a0bf into ethereum:master Nov 12, 2018
@acud acud deleted the discovery-snapshot-customservice branch November 12, 2018 15:21
@acud
Copy link
Member

acud commented Nov 12, 2018

thanks @janos i'll keep it in mind for future PRs 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants