Skip to content

Commit 960d8e5

Browse files
remove call to t.Fatal from non-test goroutine
1 parent 084744c commit 960d8e5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/mod/websocketproxy/websocketproxy_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ func TestProxy(t *testing.T) {
3737

3838
mux := http.NewServeMux()
3939
mux.Handle("/proxy", proxy)
40+
errChan := make(chan error)
4041
go func() {
4142
if err := http.ListenAndServe(":7777", mux); err != nil {
42-
t.Fatal("ListenAndServe: ", err)
43+
errChan <- err
4344
}
4445
}()
4546

46-
time.Sleep(time.Millisecond * 100)
47+
select {
48+
case err := <-errChan:
49+
t.Fatal("ListenAndServe: ", err)
50+
case <-time.After(time.Millisecond * 100):
51+
}
4752

4853
// backend echo server
4954
go func() {
@@ -73,11 +78,15 @@ func TestProxy(t *testing.T) {
7378

7479
err := http.ListenAndServe(":8888", mux2)
7580
if err != nil {
76-
t.Fatal("ListenAndServe: ", err)
81+
errChan <- err
7782
}
7883
}()
7984

80-
time.Sleep(time.Millisecond * 100)
85+
select {
86+
case err := <-errChan:
87+
t.Fatal("ListenAndServe: ", err)
88+
case <-time.After(time.Millisecond * 100):
89+
}
8190

8291
// let's us define two subprotocols, only one is supported by the server
8392
clientSubProtocols := []string{"test-protocol", "test-notsupported"}

0 commit comments

Comments
 (0)