Skip to content

Conversation

calebmer
Copy link
Collaborator

Some of the test suites are pretty slow, so this PR aims to speed up our tests. With this PR tests go from 42 seconds to 12 seconds on my machine 🎉

The secret to pretty much all of the perf wins is parallelization. Jest does not automatically parallelize tests which is fine when testing synchronous code, but is not ok for some of the heavy asynchronous tests we end up running.

We were also repeating a lot of introspection work so I tried to get clients and introspections to be shared as much as possible.

@calebmer
Copy link
Collaborator Author

It looks like tests on CI went from 30s to 10s.

@benjie
Copy link
Member

benjie commented Mar 25, 2017

Nice. Looks like we can't use snapshot tests when we're expecting errors though:

 FAIL  src/postgraphql/__tests__/postgraphqlIntegrationQueries-test.js
  ● dynamic-json.graphql
    expect(value).toMatchSnapshot()
    
    Received value does not match stored snapshot 1.
    
    - Snapshot
    + Received
    
    @@ -1,5 +1,5 @@
     Object {
       "errors": Array [
    -    [SyntaxError: Unexpected token h in JSON at position 0],
    +    [SyntaxError: Unexpected token h],
       ],
     }

}
// Await the result.
await testResults[index]
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@calebmer
Copy link
Collaborator Author

Snapshot tests are still fine. That one snapshot test failed because it looks like the error message is different in Node.js 4 then in Node.js 6, however seeing that helped me catch a bug I forgot to fix 😊

The second error causing the tests to crash is because Koa ships some ES2015 syntax in its source code that Node.js 4 doesn’t like. So the fix was to not test Koa if the Node.js major version is less than or equal to 4.

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@benjie benjie merged commit 0631012 into master Mar 26, 2017
@benjie benjie deleted the refactor/faster-tests branch March 26, 2017 19:03
Belline pushed a commit to Belline/postgraphql that referenced this pull request Dec 18, 2017
* run all of the integration tests in parallel

* move test utilities

* only introspect catalog once

* speed up some tests

* set a max workers count

* add a thing

* remove a thing to trigger build

* fix lint errors

* fix integration queries with different configurations

* only test Koa in versions of Node.js greater than 4
benjie added a commit that referenced this pull request Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants