Skip to content

Commit

Permalink
Add randomisation test for cache concurrency.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszraczylo committed Apr 8, 2023
1 parent b8044c5 commit 07e4f75
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gql

import (
"math/rand"
"reflect"
"testing"

Expand Down Expand Up @@ -413,3 +414,61 @@ func TestBaseClient_QueryCache(t *testing.T) {
})
}
}

func TestBaseClient_QueryCacheRandomizedRace(t *testing.T) {
type fields struct {
graphql_endpoint string
cache_enabled bool
}
type args struct {
queryVariables interface{}
queryHeaders map[string]interface{}
queryContent string
}
tests := []struct {
want any
args args
name string
fields fields
wantErr bool
}{
{
name: "Test QueryCache - enabled",
fields: fields{
graphql_endpoint: "https://spacex-production.up.railway.app/",
},
args: args{
queryContent: `query Dragons {
dragons {
name
}
}`,
queryHeaders: map[string]interface{}{
"x-apollo-operation-name": "Missions-Potato-Test-Golang",
"content-type": "application/json",
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewConnection()
if tt.fields.graphql_endpoint != "" {
c.endpoint = tt.fields.graphql_endpoint
}

for i := 0; i < 10; i++ {
c.cache.enabled = rand.Intn(2) == 0
go func() {
_, err := c.Query(tt.args.queryContent, tt.args.queryVariables, tt.args.queryHeaders)
if !tt.wantErr {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
}()
}
})
}
}

0 comments on commit 07e4f75

Please sign in to comment.