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

Run e2e in parallel using jest #2106

Merged
merged 6 commits into from
Mar 9, 2020
Merged

Run e2e in parallel using jest #2106

merged 6 commits into from
Mar 9, 2020

Conversation

bonomat
Copy link
Member

@bonomat bonomat commented Feb 27, 2020

Once done,
resolves #1928
resolves #1927 (I'll create a follow-up ticket to run more tests in parallel see below. Note, running multiple tests using parity is hard because we would need a mutex around sending transaction -> nonce issue )
resolves #2137

99% review please:

My assumption were:

  • we want to get rid of our custom test runner
  • we want to use jest
  • each test should have its own cnd nodes
  • tests share blockchain nodes

Ticket #1927 was partially resolved. Some tests are run in parallel but not all of them. Tests within 1 tests suite (in the same file) are not run in parallel. With this setup we can't split up all blockchain based e2e tests in multiple files though. However, I have an idea how this can be resolved. I'll create a follow-up ticket on this once this PR is merged. In short we need to do this:

  1. Start blockchain nodes and store settings in a config file
  2. For each test suite
  3. start a testenvironment which parses the config file and loads the settings into a global var
  4. execute tests
  5. Shutdown blockchain nodes after all tests

Open TODOs

  1. re-organise blockchain tests per concern tested (happy, refund, etc) and then use it.each to loop through the assets/ledgers combinations.
    The suites should probably include the protocols as those determine, which actions you can take. --> Simplify e2e tests and reuse code #2190

  2. create a follow-up ticket for parallelizing blockchain-based e2e tests: this can be quite tricky as we use 1 account for ethereum (parity-dev account) to fund each actor. --> Parallelize e2e tests and reuse code #2191

  3. create a follow-up ticket for renaming e2e tests: test names are currently a bit messy and don't necessarily have to contain - in the name. --> Rename e2e tests #2193

  4. fix LND-based sanity tests --> Fix LND-based sanity tests #2192

@bonomat bonomat added the no-mergify Stop mergify to merge this automatically label Feb 27, 2020
@mergify
Copy link
Contributor

mergify bot commented Feb 27, 2020

Are you sure the changelog does not need updating?

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Feb 27, 2020

Are you sure the changelog does not need updating?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

the tests don't terminate

Are you executing all of them or just the new ones?
Remember that we did this stupid hack with mocha where we have to call run and stuff. Maybe that is interferring with jest.
Try deleting all other tests temporarily and see if that helps.

I need to manually delete logs/bitcoind after each run, otherwise the setup fails with:

Are we using mkdir -p? That shouldn't fail if the dir already exists.

"noUnusedParameters": true,
"module": "commonjs",
"moduleResolution": "node",
"noEmit": false,
Copy link
Contributor

@thomaseizinger thomaseizinger Feb 27, 2020

Choose a reason for hiding this comment

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

That should change back to noEmit true once you are done, otherwise the folder is always cluttered with the compiled JS files.

I guess you enabled it to compile the custom test environment.
If it is only for that, we can:

  • limit the compilation to just this one file
  • find out if there is a way to feed TS to jest for the test environment
  • write the test env in JS instead of TS

Copy link
Member Author

Choose a reason for hiding this comment

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

I would need help with this. If I set it to false then TestEnvironment is not transpiled.

@bonomat

This comment has been minimized.

@thomaseizinger

This comment has been minimized.

@thomaseizinger

This comment has been minimized.

@bonomat

This comment has been minimized.

@thomaseizinger
Copy link
Contributor

The shutdown?

I am leaning towars saying it is fine. Is there a big fat error message that might confuse people?

@bonomat
Copy link
Member Author

bonomat commented Feb 27, 2020

Yes, the non-termination problem.

When I run it with this it works: yarn jest tests/e2e --forceExit
It basically terminates after the last test was run.

If I run it like this: yarn jest tests/e2e

I get the following output and it seems to never terminate:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

@thomaseizinger
Copy link
Contributor

Yes, the non-termination problem.

When I run it with this it works: yarn jest tests/e2e --forceExit
It basically terminates after the last test was run.

If I run it like this: yarn jest tests/e2e

I get the following output and it seems to never terminate:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

I just finished my task anyway. I'll checkout the PR and have a look.
Should be fine to run with --forceExit for now :)

"pretest": "cargo build --bin cnd",
"test": "ts-node ./harness.ts",
"pretest": "cargo build --bin cnd && tsc",
"test": "jest",
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

// Bitcoin/bitcoin Alpha Ledger/ Alpha Asset //
// Ethereum/ether Beta Ledger/Beta Asset //
// ******************************************** //
describe("Bitcoin/bitcoin - Ethereum/ether", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests are pretty verbose now (again) with the move of it to the outside of the twoActorTest function. I like that we can now run them through the IDE but it would also be nice if you could try and consolidate some of those function calls again.

The actual test is 4 indentation levels in :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Mhm... just thinking out lout:
What if we start 2 cnd (or depending how many we need) per test suite/test file in a beforeAll block?

This might speed up our tests and stress test cnd 😬
(not sure if this is a good idea as long as we have flaky tests though... meaning forever)

@bonomat bonomat marked this pull request as ready for review March 3, 2020 04:43
@bonomat bonomat changed the title [WIP: 50%] 1922 parallel e2e using jest Run parallel e2e using jest Mar 3, 2020
@bonomat bonomat changed the title Run parallel e2e using jest Run e2e in parallel using jest Mar 3, 2020
@bonomat bonomat requested review from D4nte and thomaseizinger March 3, 2020 04:52
@thomaseizinger

This comment has been minimized.

@mergify
Copy link
Contributor

mergify bot commented Mar 3, 2020

Are you sure the changelog does not need updating?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Good work :)

99% review coming in :D

actorNames: ["alice", "bob", "charlie"] | ["alice", "bob"] | ["alice"],
testFn: (actors: Actors) => Promise<void>
) {
const name = JasmineSmacker.getCurrentTestName();
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @luckysori look what we are finally using :D

Copy link
Member Author

Choose a reason for hiding this comment

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

I love the readme form JasmineSmacker :D

This is a very hacky solution to this issue on Jasmine's GitHub.


// ******************************************** //
// RFC003 Swap Reject //
// ******************************************** //
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this a bit odd but I guess you had your reason to add it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I find it more readable? Happy to remove it if people don't like it :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't personally like these sort of comments, they do not add anything that the function names already add and are prone to becoming stale. I am always suspicious of codebases that use these style of comments, I actually tried to get these sort of comments removed from rustc (amusingly the issue got a thumbs up, a thumbs down, and a confused :) rust-lang/rust#62601

).to.be.greaterThan(1);
});
});
it("returns-links-to-create-swap-endpoints-on-root-document-as-siren", async function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice if we could just specify regular sentences here and we just replace the dashes with hyphens for the log file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Replace spaces and slashes with dashes*

Copy link
Member Author

Choose a reason for hiding this comment

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

That'd be a lot of work. I prefer not doing it in this PR 😬

@bonomat bonomat force-pushed the 1922-parallel-e2e branch from 0d9d8de to e04e253 Compare March 6, 2020 06:47
@bonomat
Copy link
Member Author

bonomat commented Mar 6, 2020

The last commit (9f0b8a9) is a bit questionable. It was an attempt to speed things up, i.e. parallelize stuff, but it seems like it has an opposite effect.

//EDIT// seems to be only on my machine and circleCI likes it :)

@thomaseizinger
Copy link
Contributor

The last commit (9f0b8a9) is a bit questionable. It was an attempt to speed things up, i.e. parallelize stuff, but it seems like it has an opposite effect.

//EDIT// seems to be only on my machine and circleCI likes it :)

Looks fine to me :D
I compared some of the runs and it looks like that for now, we are only shaving off one minute in the e2e tests but I guess that is expected because we are actually not running anything in parallel besides the dry tests :)

Really good effort @bonomat ! Thanks for pushing through with this! It is a great foundation to build upon :)

@thomaseizinger
Copy link
Contributor

I don't know if this is included in one of your followup prs so I'll state it here again:

Reorganize the test suites (i.e. files) per concern tested (happy, refund, etc) and then use it.each to loop through the assets/ledgers combinations.

The suites should probably include the protocols as those determine, which actions you can take.

@bonomat bonomat force-pushed the 1922-parallel-e2e branch from e04e253 to c976953 Compare March 8, 2020 21:37
@bonomat
Copy link
Member Author

bonomat commented Mar 8, 2020

@da-kami , @luckysori , @rishflab , @tcharding , @D4nte , @thomaseizinger :
Can I have a 👍 if this PR builds on your machine please?
I'd also be curios about the timings on your machine 🙂

Please execute time make e2e on your machine.

I propose to get this PR merged as rebasing is starting to get annoying 😶

Note: lnd tests are skipped in this version and I propose to tackle them separately in a follow-up PR.

@tcharding
Copy link
Collaborator

tcharding commented Mar 8, 2020

Runs on my machine

make all

[snip]

Test Suites: 5 passed, 5 total
Tests:       22 passed, 22 total
Snapshots:   0 total
Time:        21.568s

[snip]

Test Suites: 1 passed, 1 total
Tests:       2 skipped, 20 passed, 22 total
Snapshots:   0 total
Time:        491.025s

@tcharding
Copy link
Collaborator

Looks like we need api_tests/dist/ added to .gitignore @bonomat.

@luckysori
Copy link
Contributor

Please execute time make e2e on your machine.

$ yarn dry && yarn e2e
$ jest --config jest.config-dry.js --maxWorkers=4
 PASS  tests/dry/multiple_peers.ts (8.509s)
 PASS  tests/dry/peers_using_ip.ts (11.941s)
 PASS  tests/dry/lightning_routes.ts (5.005s)
 PASS  tests/dry/rfc003_schema.ts (13.915s)
 PASS  tests/dry/sanity.ts (16.462s)

Test Suites: 5 passed, 5 total
Tests:       22 passed, 22 total
Snapshots:   0 total
Time:        17.308s
Ran all test suites.
A worker process has failed to exit gracefully and has been force exited. This is l
er teardown. Try running with --runInBand --detectOpenHandles to find leaks.
$ yarn jest --config jest.config-e2e.js --runInBand --forceExit --bail
$ /home/luckysori/work/comit-network/comit-rs/api_tests/node_modules/.bin/jest --co
Exit --bail
Starting ledger ethereum
Starting ledger bitcoin
(node:30253) MaxListenersExceededWarning: Possible EventEmitter memory leak detecte
Use emitter.setMaxListeners() to increase limit
 PASS  tests/e2e/bitcoin_ethereum.ts (492.235s)
  E2E: Sanity - LND Alice pays Bob
    ○ skipped sanity-lnd-alice-pays-bob
    ○ skipped sanity-lnd-alice-pays-bob-using-hold-invoice
  E2E: Bitcoin/bitcoin - Ethereum/ether
    ✓ rfc003-btc-eth-alice-redeems-bob-redeems (20752ms)
    ✓ rfc003-btc-eth-bob-refunds-alice-refunds (24926ms)
    ✓ rfc003-btc-eth-alice-refunds-bob-refunds (28823ms)
    ✓ rfc003-btc-eth-cnd-can-be-restarted (8208ms)
    ✓ rfc003-btc-eth-resume-alice-down-bob-funds (25272ms)
    ✓ rfc003-btc-eth-resume-alice-down-bob-redeems (23177ms)
    ✓ rfc003-btc-eth-resume-bob-down-alice-funds (25303ms)
    ✓ rfc003-btc-eth-resume-bob-down-alice-redeems (25375ms)
    ✓ rfc003-btc-eth-alice-underfunds-bob-aborts (28312ms)
    ✓ rfc003-btc-eth-bob-underfunds-both-refund (24970ms)
    ✓ rfc003-btc-eth-alice-overfunds-bob-aborts (27414ms)
    ✓ rfc003-btc-eth-bob-overfunds-both-refund (25104ms)
  E2E: Ethereum/ether - Bitcoin/bitcoin
    ✓ rfc003-eth-btc-alice-redeems-bob-redeems (22468ms)
    ✓ rfc003-eth-btc-alpha-deploy-fails (19900ms)
    ✓ rfc003-eth-btc-bob-refunds-alice-refunds (22090ms)
    ✓ rfc003-eth-btc-alice-redeems-with-high-fee (15862ms)
  E2E: Bitcoin/bitcoin - Ethereum/erc20
    ✓ rfc003-btc-eth-erc20-alice-redeems-bob-redeems (25614ms)
    ✓ rfc003-btc-eth-erc20-bob-refunds-alice-refunds (32996ms)
  E2E: Ethereum/erc20 - Bitcoin/bitcoin
    ✓ rfc003-eth-erc20_btc-alice-redeems-bob-redeems (27059ms)
    ✓ rfc003-eth-erc20_btc-bob-refunds-alice-refunds (30014ms)

Test Suites: 1 passed, 1 total
Tests:       2 skipped, 20 passed, 22 total
Snapshots:   0 total
Time:        492.703s
Ran all test suites.
Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async
 operations that kept running after all tests finished?
Done in 514.08s.

@bonomat
Copy link
Member Author

bonomat commented Mar 9, 2020

From @rishflab :

Starting ledger ethereum
Starting ledger bitcoin
(node:54087) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
 PASS tests/e2e/bitcoin_ethereum.ts (627.947s)
  E2E: Sanity - LND Alice pays Bob
    ○ skipped sanity-lnd-alice-pays-bob
    ○ skipped sanity-lnd-alice-pays-bob-using-hold-invoice
  E2E: Bitcoin/bitcoin - Ethereum/ether
    ✓ rfc003-btc-eth-alice-redeems-bob-redeems (25564ms)
    ✓ rfc003-btc-eth-bob-refunds-alice-refunds (29002ms)
    ✓ rfc003-btc-eth-alice-refunds-bob-refunds (31820ms)
    ✓ rfc003-btc-eth-cnd-can-be-restarted (23512ms)
    ✓ rfc003-btc-eth-resume-alice-down-bob-funds (34478ms)
    ✓ rfc003-btc-eth-resume-alice-down-bob-redeems (32420ms)
    ✓ rfc003-btc-eth-resume-bob-down-alice-funds (34448ms)
    ✓ rfc003-btc-eth-resume-bob-down-alice-redeems (34458ms)
    ✓ rfc003-btc-eth-alice-underfunds-bob-aborts (33268ms)
    ✓ rfc003-btc-eth-bob-underfunds-both-refund (29417ms)
    ✓ rfc003-btc-eth-alice-overfunds-bob-aborts (32969ms)
    ✓ rfc003-btc-eth-bob-overfunds-both-refund (29092ms)
  E2E: Ethereum/ether - Bitcoin/bitcoin
    ✓ rfc003-eth-btc-alice-redeems-bob-redeems (28093ms)
    ✓ rfc003-eth-btc-alpha-deploy-fails (24510ms)
    ✓ rfc003-eth-btc-bob-refunds-alice-refunds (26836ms)
    ✓ rfc003-eth-btc-alice-redeems-with-high-fee (20872ms)
  E2E: Bitcoin/bitcoin - Ethereum/erc20
    ✓ rfc003-btc-eth-erc20-alice-redeems-bob-redeems (34485ms)
    ✓ rfc003-btc-eth-erc20-bob-refunds-alice-refunds (36811ms)
  E2E: Ethereum/erc20 - Bitcoin/bitcoin
    ✓ rfc003-eth-erc20_btc-alice-redeems-bob-redeems (33816ms)
    ✓ rfc003-eth-erc20_btc-bob-refunds-alice-refunds (34110ms)

Test Suites: 1 passed, 1 total
Tests:       2 skipped, 20 passed, 22 total
Snapshots:   0 total
Time:        628.67s
Ran all test suites.
Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?
✨  Done in 697.30s.

Copy link
Member

@da-kami da-kami left a comment

Choose a reason for hiding this comment

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

passed on my machine

Output stats:

Test Suites: 1 passed, 1 total
Tests:       2 skipped, 20 passed, 22 total
Snapshots:   0 total
Time:        634.555s
Ran all test suites.
Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?
✨  Done in 708.52s.

@bonomat
Copy link
Member Author

bonomat commented Mar 9, 2020

Works on everyone's machine. I'll create some follow-up tickets.

@bonomat bonomat removed the no-mergify Stop mergify to merge this automatically label Mar 9, 2020
@bonomat
Copy link
Member Author

bonomat commented Mar 9, 2020

bors r+

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Mar 9, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 9, 2020

Already running a review

@bors
Copy link
Contributor

bors bot commented Mar 9, 2020

Build succeeded

@bors bors bot merged commit 7d634a6 into dev Mar 9, 2020
@mergify mergify bot deleted the 1922-parallel-e2e branch March 9, 2020 01:08
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.

e2e tests start too many cnds No custom e2e test runner Run the e2e tests in parallel
6 participants