Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c965c73

Browse files
committed
fix: fix hang in teardown of TestConn_CoordinatorRollingRestart
1 parent 103824f commit c965c73

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

enterprise/coderd/coderd_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -852,30 +852,26 @@ func TestConn_CoordinatorRollingRestart(t *testing.T) {
852852
}
853853

854854
func tcpEchoServer(t *testing.T) string {
855-
var listenerWg sync.WaitGroup
856855
tcpListener, err := net.Listen("tcp", "127.0.0.1:0")
857856
require.NoError(t, err)
858857
t.Cleanup(func() {
859858
_ = tcpListener.Close()
860-
listenerWg.Wait()
861859
})
862-
listenerWg.Add(1)
863860
go func() {
864-
defer listenerWg.Done()
865861
for {
866862
conn, err := tcpListener.Accept()
867863
if err != nil {
868864
return
869865
}
870-
listenerWg.Add(1)
866+
t.Cleanup(func() {
867+
_ = conn.Close()
868+
})
871869
go func() {
872-
defer listenerWg.Done()
873870
defer conn.Close()
874871
_, _ = io.Copy(conn, conn)
875872
}()
876873
}
877874
}()
878-
879875
return tcpListener.Addr().String()
880876
}
881877

0 commit comments

Comments
 (0)