Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix go vet warnings: call to (*T).Fatalf from a non-test goroutine #166

Merged
merged 1 commit into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions streaming_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
)
Expand All @@ -29,11 +30,14 @@ event: delete
data: 1234567
:thump
`, largeContent))
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
defer close(q)
err := handleReader(q, r)
if err != nil {
t.Fatalf("should not be fail: %v", err)
t.Errorf("should not be fail: %v", err)
}
}()
var passUpdate, passUpdateLarge, passNotification, passDelete, passError bool
Expand Down Expand Up @@ -69,6 +73,7 @@ data: 1234567
"update: %t, update (large): %t, notification: %t, delete: %t, error: %t",
passUpdate, passUpdateLarge, passNotification, passDelete, passError)
}
wg.Wait()
}

func TestStreaming(t *testing.T) {
Expand Down Expand Up @@ -148,11 +153,14 @@ func TestDoStreaming(t *testing.T) {
req = req.WithContext(ctx)

q := make(chan Event)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
defer close(q)
c.doStreaming(req, q)
if err != nil {
t.Fatalf("should not be fail: %v", err)
t.Errorf("should not be fail: %v", err)
}
}()
var passError bool
Expand All @@ -167,6 +175,7 @@ func TestDoStreaming(t *testing.T) {
if !passError {
t.Fatalf("have not passed through: error %t", passError)
}
wg.Wait()
}

func TestStreamingUser(t *testing.T) {
Expand Down
22 changes: 18 additions & 4 deletions streaming_ws_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -151,12 +152,16 @@ func TestStreamingWS(t *testing.T) {
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.err)
}
}()
wg.Wait()
}

func TestHandleWS(t *testing.T) {
Expand All @@ -183,10 +188,13 @@ func TestHandleWS(t *testing.T) {
q := make(chan Event)
client := NewClient(&Config{}).NewWSClient()

var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.err)
}
}()
err := client.handleWS(context.Background(), ":", q)
Expand All @@ -196,24 +204,30 @@ func TestHandleWS(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
cancel()
wg.Add(1)
go func() {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.err)
}
}()
err = client.handleWS(ctx, "ws://"+ts.Listener.Addr().String(), q)
if err == nil {
t.Fatalf("should be fail: %v", err)
}

wg.Add(1)
go func() {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.err)
}
}()
client.handleWS(context.Background(), "ws://"+ts.Listener.Addr().String(), q)

wg.Wait()
}

func TestDialRedirect(t *testing.T) {
Expand Down