Skip to content

Commit

Permalink
Add a stress test on query cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Oct 2, 2018
1 parent 23b58f6 commit bab70df
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions handler/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ func TestHandlerPOST(t *testing.T) {
assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String())
})

t.Run("query caching", func(t *testing.T) {
// Run enough unique queries to evict a bunch of them
for i := 0; i < 2000; i++ {
query := `{"query":"` + strings.Repeat(" ", i) + "{ me { name } }" + `"}`
resp := doRequest(h, "POST", "/graphql", query)
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String())
}

t.Run("evicted queries run", func(t *testing.T) {
query := `{"query":"` + strings.Repeat(" ", 0) + "{ me { name } }" + `"}`
resp := doRequest(h, "POST", "/graphql", query)
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String())
})

t.Run("non-evicted queries run", func(t *testing.T) {
query := `{"query":"` + strings.Repeat(" ", 1999) + "{ me { name } }" + `"}`
resp := doRequest(h, "POST", "/graphql", query)
assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String())
})
})

t.Run("decode failure", func(t *testing.T) {
resp := doRequest(h, "POST", "/graphql", "notjson")
assert.Equal(t, http.StatusBadRequest, resp.Code)
Expand Down

0 comments on commit bab70df

Please sign in to comment.