Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Retry connection in the test
Browse files Browse the repository at this point in the history
Signed-off-by: Chris O'Hara <[email protected]>
  • Loading branch information
chriso committed Jul 12, 2023
1 parent 2339f0a commit ffb9ed2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions testdata/go/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
err = fmt.Errorf("usage: spawn.wasm [worker]")
}
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v", err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
Expand Down Expand Up @@ -57,16 +57,22 @@ func supervisor(ctx context.Context) error {
}
defer client.Kill(ctx, workerID)

fmt.Printf("spawned worker process %s with address %s\n", workerID, workerAddr)

// FIXME:
time.Sleep(2 * time.Second)
fmt.Printf("connecting to worker process %s on address %s\n", workerID, workerAddr)

httpClient := &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
DialContext: func(ctx context.Context, network, addr string) (conn net.Conn, err error) {
var d wasip1.Dialer
return d.DialContext(ctx, network, addr)
const delay = 300 * time.Millisecond
const attempts = 10 // try for 3 seconds
for i := 0; i < attempts; i++ {
conn, err = d.DialContext(ctx, network, addr)
if err == nil {
break
}
time.Sleep(delay)
}
return
},
},
}
Expand Down

0 comments on commit ffb9ed2

Please sign in to comment.