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

cmd/geth/tests: try to fix spurious travis failure in les tests #21410

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/geth/les_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (g *gethrpc) waitSynced() {
}
}

func startGethWithRpc(t *testing.T, name string, args ...string) *gethrpc {
func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
g := &gethrpc{name: name}
args = append([]string{"--networkid=42", "--port=0", "--nousb", "--http", "--http.port=0", "--http.api=admin,eth,les"}, args...)
args = append([]string{"--networkid=42", "--port=0", "--nousb"}, args...)
t.Logf("Starting %v with rpc: %v", name, args)
g.geth = runGeth(t, args...)
// wait before we can attach to it. TODO: probe for it properly
Expand All @@ -112,23 +112,23 @@ func startGethWithRpc(t *testing.T, name string, args ...string) *gethrpc {
}

func initGeth(t *testing.T) string {
g := runGeth(t, "--networkid=42", "init", "./testdata/clique.json")
g := runGeth(t, "--nousb", "--networkid=42", "init", "./testdata/clique.json")
datadir := g.Datadir
g.WaitExit()
return datadir
}

func startLightServer(t *testing.T) *gethrpc {
datadir := initGeth(t)
runGeth(t, "--datadir", datadir, "--password", "./testdata/password.txt", "account", "import", "./testdata/key.prv").WaitExit()
runGeth(t, "--nousb", "--datadir", datadir, "--password", "./testdata/password.txt", "account", "import", "./testdata/key.prv").WaitExit()
account := "0x02f0d131f1f97aef08aec6e3291b957d9efe7105"
server := startGethWithRpc(t, "lightserver", "--allow-insecure-unlock", "--datadir", datadir, "--password", "./testdata/password.txt", "--unlock", account, "--mine", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
server := startGethWithIpc(t, "lightserver", "--allow-insecure-unlock", "--datadir", datadir, "--password", "./testdata/password.txt", "--unlock", account, "--mine", "--light.serve=100", "--light.maxpeers=1", "--nodiscover", "--nat=extip:127.0.0.1")
return server
}

func startClient(t *testing.T, name string) *gethrpc {
datadir := initGeth(t)
return startGethWithRpc(t, name, "--datadir", datadir, "--nodiscover", "--syncmode=light", "--nat=extip:127.0.0.1")
return startGethWithIpc(t, name, "--datadir", datadir, "--nodiscover", "--syncmode=light", "--nat=extip:127.0.0.1")
}

func TestPriorityClient(t *testing.T) {
Expand Down Expand Up @@ -166,6 +166,7 @@ func TestPriorityClient(t *testing.T) {
freeCli.getNodeInfo().ID: freeCli,
prioCli.getNodeInfo().ID: prioCli,
}
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps to move this sleeping after here https://github.com/ethereum/go-ethereum/pull/21410/files#diff-2fa5be81f9d5e118c5960933593a41c0R157

Then we can ensure the previous client is kicked out, the new client is accepted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Myeah, maybe if this doesn't fix it. In general, it seems pretty flakey. For example, I fixed the startGeth to not blindly wait, but instead poll until the ipc socket opened up -- the test ran much faster, but also failed a lot more.
It would be nice to have some better guarantees about syncronicity, but for now we have these sleeps on odd places.

lightServer.callRPC(&peers, "admin_peers")
peersWithNames := make(map[string]string)
for _, p := range peers {
Expand Down