Skip to content

Commit 0e69613

Browse files
authored
cmd/geth: fix IPC probe in les test (ethereum#23094)
Previously, the test waited a second and then failed if geth had not started. This caused the test to fail intermittently. This change checks whether the IPC is open 10 times over a 5 second period and then fails if geth is still not available.
1 parent 948a600 commit 0e69613

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cmd/geth/les_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,18 @@ func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
137137
name: name,
138138
geth: runGeth(t, args...),
139139
}
140-
// wait before we can attach to it. TODO: probe for it properly
141-
time.Sleep(1 * time.Second)
142-
var err error
143140
ipcpath := ipcEndpoint(ipcName, g.geth.Datadir)
144-
if g.rpc, err = rpc.Dial(ipcpath); err != nil {
145-
t.Fatalf("%v rpc connect to %v: %v", name, ipcpath, err)
141+
// We can't know exactly how long geth will take to start, so we try 10
142+
// times over a 5 second period.
143+
var err error
144+
for i := 0; i < 10; i++ {
145+
time.Sleep(500 * time.Millisecond)
146+
if g.rpc, err = rpc.Dial(ipcpath); err == nil {
147+
return g
148+
}
146149
}
147-
return g
150+
t.Fatalf("%v rpc connect to %v: %v", name, ipcpath, err)
151+
return nil
148152
}
149153

150154
func initGeth(t *testing.T) string {

0 commit comments

Comments
 (0)