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 flaky test TestSubscriptions #2779

Merged
merged 2 commits into from
Sep 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions codegen/testserver/followschema/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func TestSubscriptions(t *testing.T) {
})

t.Run("will parse init payload", func(t *testing.T) {
runtime.GC() // ensure no go-routines left from preceding tests
initialGoroutineCount := runtime.NumGoroutine()

sub := c.WebsocketWithPayload(`subscription { initPayload }`, map[string]interface{}{
"Authorization": "Bearer of the curse",
"number": 32,
Expand All @@ -155,6 +158,14 @@ func TestSubscriptions(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "strings = []interface {}{\"hello\", \"world\"}", msg.resp.InitPayload)
sub.Close()

// need a little bit of time for goroutines to settle
start := time.Now()
for time.Since(start).Seconds() < 2 && initialGoroutineCount != runtime.NumGoroutine() {
time.Sleep(5 * time.Millisecond)
}

require.Equal(t, initialGoroutineCount, runtime.NumGoroutine())
})

t.Run("websocket gets errors", func(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions codegen/testserver/singlefile/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func TestSubscriptions(t *testing.T) {
})

t.Run("will parse init payload", func(t *testing.T) {
runtime.GC() // ensure no go-routines left from preceding tests
initialGoroutineCount := runtime.NumGoroutine()

sub := c.WebsocketWithPayload(`subscription { initPayload }`, map[string]interface{}{
"Authorization": "Bearer of the curse",
"number": 32,
Expand All @@ -155,6 +158,14 @@ func TestSubscriptions(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "strings = []interface {}{\"hello\", \"world\"}", msg.resp.InitPayload)
sub.Close()

// need a little bit of time for goroutines to settle
start := time.Now()
for time.Since(start).Seconds() < 2 && initialGoroutineCount != runtime.NumGoroutine() {
time.Sleep(5 * time.Millisecond)
}

require.Equal(t, initialGoroutineCount, runtime.NumGoroutine())
})

t.Run("websocket gets errors", func(t *testing.T) {
Expand Down