From c049ca68ab0b83eedcea74e39d3326a39c986b65 Mon Sep 17 00:00:00 2001
From: Marten Seemann <martenseemann@gmail.com>
Date: Sun, 15 May 2022 15:54:35 +0200
Subject: [PATCH] quic: deflake the holepunching test

---
 p2p/transport/quic/conn_test.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/p2p/transport/quic/conn_test.go b/p2p/transport/quic/conn_test.go
index e5faf09b32..89d9db15e4 100644
--- a/p2p/transport/quic/conn_test.go
+++ b/p2p/transport/quic/conn_test.go
@@ -550,7 +550,13 @@ func TestHolePunching(t *testing.T) {
 	// Make sure the server role (the dial on t2) has progressed far enough.
 	// If it hasn't created the hole punch map entry, the connection will be accepted as a regular connection,
 	// which would make this test fail.
-	time.Sleep(25 * time.Millisecond)
+	require.Eventually(t, func() bool {
+		tr := t2.(*transport)
+		tr.holePunchingMx.Lock()
+		defer tr.holePunchingMx.Unlock()
+		return len(tr.holePunching) > 0
+	}, time.Second, 10*time.Millisecond)
+
 	conn1, err := t1.Dial(
 		network.WithSimultaneousConnect(context.Background(), true, ""),
 		ln2.Multiaddr(),