Don't call "Fatal" from inside a goroutine.

This commit is contained in:
Joachim Bauch 2020-07-31 15:19:11 +02:00
parent 67c5bebdcb
commit efc232fb9c
Failed to extract signature
3 changed files with 23 additions and 10 deletions

View File

@ -1068,11 +1068,13 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
data, err := json.Marshal(msg)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
res, err := performBackendRequest(server.URL+"/api/v1/room/"+roomId, data)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
@ -1119,11 +1121,13 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
data, err := json.Marshal(msg)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
res, err := performBackendRequest(server.URL+"/api/v1/room/"+roomId, data)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
@ -1136,6 +1140,9 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
}()
wg.Wait()
if t.Failed() {
return
}
msg1_a, err := client1.RunUntilMessage(ctx)
if err != nil {

View File

@ -88,7 +88,8 @@ func TestLoopbackNatsClient_Subscribe(t *testing.T) {
if total == max {
err := sub.Unsubscribe()
if err != nil {
t.Fatal("Unsubscribe failed with err:", err)
t.Errorf("Unsubscribe failed with err: %s", err)
return
}
ch <- true
}
@ -135,10 +136,12 @@ func TestLoopbackNatsClient_Request(t *testing.T) {
go func() {
msg := <-dest
if err := client.Publish(msg.Reply, []byte("world")); err != nil {
t.Fatal(err)
t.Error(err)
return
}
if err := sub.Unsubscribe(); err != nil {
t.Fatal("Unsubscribe failed with err:", err)
t.Error("Unsubscribe failed with err:", err)
return
}
}()
reply, err := client.Request("foo", []byte("hello"), 1*time.Second)
@ -182,10 +185,12 @@ func TestLoopbackNatsClient_RequestTimeout(t *testing.T) {
msg := <-dest
time.Sleep(200 * time.Millisecond)
if err := client.Publish(msg.Reply, []byte("world")); err != nil {
t.Fatal(err)
t.Error(err)
return
}
if err := sub.Unsubscribe(); err != nil {
t.Fatal("Unsubscribe failed with err:", err)
t.Error("Unsubscribe failed with err:", err)
return
}
}()
reply, err := client.Request("foo", []byte("hello"), 100*time.Millisecond)

View File

@ -233,7 +233,8 @@ func NewTestClient(t *testing.T, server *httptest.Server, hub *Hub) *TestClient
readErrorChan <- err
return
} else if messageType != websocket.TextMessage {
t.Fatalf("Expect text message, got %d", messageType)
t.Errorf("Expect text message, got %d", messageType)
return
}
messageChan <- data