From 8217b1f094e5bb0cf8d3d5740e8ea9b3f1997ce1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 3 Aug 2021 13:36:29 -0700 Subject: [PATCH] fix: deflake multipro echo test Specifically, wait for the handlers to finish printing before exiting. --- examples/multipro/echo.go | 1 + examples/multipro/main.go | 2 +- examples/multipro/ping.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/multipro/echo.go b/examples/multipro/echo.go index e9b58bcf..214242e3 100644 --- a/examples/multipro/echo.go +++ b/examples/multipro/echo.go @@ -86,6 +86,7 @@ func (e *EchoProtocol) onEchoRequest(s network.Stream) { if ok { log.Printf("%s: Echo response to %s sent.", s.Conn().LocalPeer().String(), s.Conn().RemotePeer().String()) } + e.done <- true } // remote echo response handler diff --git a/examples/multipro/main.go b/examples/multipro/main.go index 27b49735..fbfe4990 100644 --- a/examples/multipro/main.go +++ b/examples/multipro/main.go @@ -57,7 +57,7 @@ func run(h1, h2 *Node, done <-chan bool) { h2.Echo(h1.Host) // block until all responses have been processed - for i := 0; i < 4; i++ { + for i := 0; i < 8; i++ { <-done } } diff --git a/examples/multipro/ping.go b/examples/multipro/ping.go index 43666bc9..e5820a9d 100644 --- a/examples/multipro/ping.go +++ b/examples/multipro/ping.go @@ -82,6 +82,7 @@ func (p *PingProtocol) onPingRequest(s network.Stream) { if ok { log.Printf("%s: Ping response to %s sent.", s.Conn().LocalPeer().String(), s.Conn().RemotePeer().String()) } + p.done <- true } // remote ping response handler