Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Make integration tests atomic #302

Closed
wants to merge 1 commit into from

Conversation

danielrearden
Copy link
Contributor

Addresses #252. Summary of changes:

  • Added a .graphml file exported from the current database used for the tests
  • Added a beforeEach hook to the integration tests that wipes the database and then imports the data from file
  • Refactored the integration tests to run atomically. In addition to forcing the tests to run serially, I also moved any required set up (i.e. creating the node being mutated or queried) to inside each test.
  • Updated some of the queries in the integration tests to include orderBy arguments to ensure the tests are deterministic regardless of internal node id
  • Updated the scripts to include some additional lines to neo4j.conf necessary to use apoc.import.graphml

Some additional considerations:

  • Outside of improving the tests themselves, this also means the tests can be ran multiple times without having to re-import the database. In fact, it's not necessary to import the data at all when setting up the dev environment. Importing the data from the repo is itself a big plus too, especially if the data needs to be changed in the future.
  • Running the tests serially slows down the suite considerably, especially with the hook. Ideally we'd be able to run the tests concurrently, but this would require each test to run against its own database instance. Even with this approach, though, I think the benefits outweigh the cost in performance.
  • There's some redundancy between the tests with regard to setup. Ideally, we'd move the setup for each test inside a hook but since ava doesn't support grouping like mocha or jest, this is a bit tricky to do.
  • If the integration tests are broken into multiple files, they will need to be run with the --serial flag :(

await resetDatabase();
});

test.serial('hello world', t => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this test be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup - feel free to delete that :-)

@johnymontana
Copy link
Contributor

Hey @danielrearden - this looks great, thanks so much.

The only concern I have is that since the resetDatabase function does a MATCH (n) DETACH DELETE n that there is the possibility someone could run the integration tests and inadvertently wipe out a database they had running and didn't intend to use for testing. Of course, they would have to have set the password to letmein, but could we add a warning making this clear? Perhaps in contributing.md?

@codecov-io
Copy link

codecov-io commented Sep 4, 2019

Codecov Report

Merging #302 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #302   +/-   ##
=======================================
  Coverage   95.48%   95.48%           
=======================================
  Files          10       10           
  Lines        2346     2346           
=======================================
  Hits         2240     2240           
  Misses        106      106

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47a5d53...063ed56. Read the comment docs.

@danielrearden
Copy link
Contributor Author

@johnymontana I've updated the query inside resetDatabase to match only on nodes with labels relevant to the integration tests.

roschaefer added a commit to roschaefer/neo4j-graphql-js that referenced this pull request Sep 13, 2019
@roschaefer
Copy link
Contributor

@johnymontana @danielrearden see here 👉 danielrearden#1

@danielrearden
Copy link
Contributor Author

@roschaefer Thanks, will try to get that merged ASAP

@johnymontana
Copy link
Contributor

Hey @danielrearden ping to see if you can merge in @roschaefer commits and then I can get these PR merged?

@danielrearden
Copy link
Contributor Author

@johnymontana So sorry! This PR totally dropped off my radar. I'm going to close this for now since it would take a good chunk of work to resolve the merge conflicts and I don't have the bandwidth to do that at the moment. However, if this change is still needed, I can take another crack at it in the future.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants