cmd/geth, internal: fix flaky console tests

This commit is contained in:
Gary Rong 2025-05-08 14:41:28 +08:00
parent 0d5de826da
commit 032ef0e84c
3 changed files with 5 additions and 5 deletions

View file

@ -102,17 +102,17 @@ func TestAttachWelcome(t *testing.T) {
"--http", "--http.port", httpPort,
"--ws", "--ws.port", wsPort)
t.Run("ipc", func(t *testing.T) {
waitForEndpoint(t, ipc, 4*time.Second)
waitForEndpoint(t, ipc, 2*time.Minute)
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)
})
t.Run("http", func(t *testing.T) {
endpoint := "http://127.0.0.1:" + httpPort
waitForEndpoint(t, endpoint, 4*time.Second)
waitForEndpoint(t, endpoint, 2*time.Minute)
testAttachWelcome(t, geth, endpoint, httpAPIs)
})
t.Run("ws", func(t *testing.T) {
endpoint := "ws://127.0.0.1:" + wsPort
waitForEndpoint(t, endpoint, 4*time.Second)
waitForEndpoint(t, endpoint, 2*time.Minute)
testAttachWelcome(t, geth, endpoint, httpAPIs)
})
geth.Kill()

View file

@ -97,7 +97,7 @@ func runGeth(t *testing.T, args ...string) *testgeth {
// waitForEndpoint attempts to connect to an RPC endpoint until it succeeds.
func waitForEndpoint(t *testing.T, endpoint string, timeout time.Duration) {
probe := func() bool {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c, err := rpc.DialContext(ctx, endpoint)
if c != nil {

View file

@ -237,7 +237,7 @@ func (tt *TestCmd) Kill() {
}
func (tt *TestCmd) withKillTimeout(fn func()) {
timeout := time.AfterFunc(30*time.Second, func() {
timeout := time.AfterFunc(2*time.Minute, func() {
tt.Log("killing the child process (timeout)")
tt.Kill()
})