Skip to content

Commit c095d71

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

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/mod/websocketproxy/websocketproxy_test.go

Lines changed: 14 additions & 5 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() {
41-
if err := http.ListenAndServe(":7777", mux); err != nil {
42-
t.Fatal("ListenAndServe: ", err)
42+
if err := http.ListenAndServe(":443", mux); err != nil {
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.Second):
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.Second):
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)