Skip to content

Commit

Permalink
Fixed test that randomly fails due to variablity of goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Heatwole committed Feb 15, 2019
1 parent 8f44e53 commit 66b396a
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"runtime"
"sort"
"sync"
"testing"
"time"

"github.com/99designs/gqlgen/graphql/introspection"

"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/handler"
"github.com/fortytw2/leaktest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -125,7 +123,7 @@ func TestGeneratedServer(t *testing.T) {

t.Run("subscriptions", func(t *testing.T) {
t.Run("wont leak goroutines", func(t *testing.T) {
initialGoroutineCount := runtime.NumGoroutine()
defer leaktest.Check(t)()

sub := c.Websocket(`subscription { updated }`)

Expand All @@ -141,14 +139,6 @@ func TestGeneratedServer(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "message", msg.resp.Updated)
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("will parse init payload", func(t *testing.T) {
Expand Down

0 comments on commit 66b396a

Please sign in to comment.