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

Close all handles during Jest teardown #2330

Merged
merged 6 commits into from Mar 30, 2020
Merged

Close all handles during Jest teardown #2330

merged 6 commits into from Mar 30, 2020

Conversation

luckysori
Copy link
Contributor

@luckysori luckysori commented Mar 26, 2020

Waiting for comit-network/comit-js-sdk#176 to be merged and for those changes to be included in a release of comit-js-sdk before we can update the last commit in this PR to use that release instead of a local dependency created via yalc (which seems to work much better than yarn link).

Fixes #2211.

  1. Turns out Jest will hang until every timeout is cleared, so racing against a timeout that is only cleared after it resolves was not good.
  2. The proper teardown of the e2e test environment is fully achieved with 3698f3a, after a lot of debugging. Unfortunately, Jest recommends this
Consider running Jest with `--detectOpenHandles` to troubleshoot this issue

when tests hang after passing, but it just doesn't seem to do anything. I tried using leaked-handles without success, but finally found wtfnode, which identified bcoin as the culprit.


My OCD was definitely triggered with this one, as a different error got me to investigate how to get rid of smack-my-jasmine-up. Turns out removing it did not fix that other error, but I still see it as a win, since depending on such an obscure library is bad.


And another bug squashed! No more

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit

errors, by combining cde8e0c and 127a4a2:

  • shutting down the logger during teardown.
  • closing log files after 5 seconds of inactivity, to prevent us from reaching the limit of listeners.

I believe log files can be reopened if something else needs to be logged.

@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2020

Are you sure the changelog does not need updating?

2 similar comments
@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2020

Are you sure the changelog does not need updating?

@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2020

Are you sure the changelog does not need updating?

@bonomat
Copy link
Member

bonomat commented Mar 26, 2020

smack-my-jasmine-up always annoyed me a bit aswell.
So what's your strategy here now as your PR does not seem to build?

@luckysori
Copy link
Contributor Author

smack-my-jasmine-up always annoyed me a bit aswell.
So what's your strategy here now as your PR does not seem to build?

Silly me, forgot to do the same for e2e tests (not just dry)!

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.

You are a genius Lucas :)
Go job figuring that one out!

reject(new Error(`timed out after ${ms}ms`));
}, ms);
});

// Returns a race between our timeout and the passed in promise
return Promise.race([promise, timeout]);
return Promise.race([promise, timeout]).then((result) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we maybe use .finally here, just to be sure?

@luckysori luckysori changed the title Clear timeout even if race resolves before timeout Close all handles during Jest teardown Mar 29, 2020
@bonomat bonomat added the no-mergify Stop mergify to merge this automatically label Mar 29, 2020
@@ -0,0 +1,5 @@
jasmine.getEnv().addReporter({
specStarted: (result) =>
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get typings for this instead of using ts-ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe you can help me figure this one out.

I now realise that I'm using the jasmine namespace to set and read a value which wasn't there in the first place i.e. there is no type because I'm creating that "field".

Would it make more sense to save this to the global context of the e2e test suite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make more sense to save this to the global context of the e2e test suite?

I guess not because this global context can be accessed by two tests running concurrently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just gonna leave this one as an optional follow-up PR. Had a look at merging namespaces to extend the one provided by jest with the type we need here, but there's probably a much easier approach that I'm missing!

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess not because this global context can be accessed by two tests running concurrently.

The test environment provides a unique instance of global to every test so you can safely set things there!

Copy link
Contributor

Choose a reason for hiding this comment

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

But yes, we can do this as a follow-up. I don't have time at the moment so you could write a short issue please? :)

api_tests/src/e2e_test_environment.ts Show resolved Hide resolved
api_tests/src/utils.ts Outdated Show resolved Hide resolved
@thomaseizinger
Copy link
Contributor

So many good fixes in this one :)

bors bot added a commit to comit-network/comit-js-sdk that referenced this pull request Mar 30, 2020
176: Add close method for bcoin wallet r=mergify[bot] a=luckysori

These are a couple of patches that need to be released before comit-network/comit-rs#2330 can be merged in.

Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
api_tests/package.json Outdated Show resolved Hide resolved
`yalc` seems more reliable than `yarn link`.
This allows us to remove the weird `smack-my-jasmine-up` dependency.
We ensure that all nodes are stopped and all wallets are closed during
Jest teardown.
To prevent reaching the limit of listeners.
@luckysori luckysori removed the no-mergify Stop mergify to merge this automatically label Mar 30, 2020
@luckysori luckysori requested a review from bonomat March 30, 2020 03:30
Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

Good job.

@bonomat
Copy link
Member

bonomat commented Mar 30, 2020

bors r+

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Mar 30, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 30, 2020

Already running a review

@bors
Copy link
Contributor

bors bot commented Mar 30, 2020

Build succeeded

@bors bors bot merged commit 23dda65 into dev Mar 30, 2020
luckysori added a commit to comit-network/comit-js-sdk that referenced this pull request Mar 31, 2020
Motivated by the combination of wanting to test
`tryExecuteSirenAction` and realising that we would just be testing
`timeoutPromise`. We have already decided to replace exactly the same
function in
`comit-rs` (comit-network/comit-rs#2330 (comment)),
so replacing it here has the nice consequence of not needing to write
a new test, since it's not our own code.

Side-effects:

- Move `TryParams` to `swap.ts` since it's directly related and only
  used for executing a swap.
- Rename `util/timeout_promise.ts` to `util/sleep.ts`, since it now
  only holds a `sleep` function.
bors bot added a commit to comit-network/comit-js-sdk that referenced this pull request Mar 31, 2020
179: Replace timeout function with external dependency r=mergify[bot] a=luckysori

Fixes #120 (imo).

## Straight from the commit

Motivated by the combination of wanting to test `tryExecuteSirenAction` and realising that we would just be testing `timeoutPromise`. We have already decided to replace exactly the same function in
`comit-rs` (comit-network/comit-rs#2330 (comment)), so replacing it here has the nice consequence of not needing to write a new test, since it's not our own code.

Side-effects:

- Move `TryParams` to `swap.ts` since it's directly related and only used for executing a swap.
- Rename `util/timeout_promise.ts` to `util/sleep.ts`, since it now only holds a `sleep` function.

## Notes

I don't believe this requires a changelog update. Am I wrong?

Co-authored-by: Lucas Soriano del Pino <l.soriano.del.pino@gmail.com>
@thomaseizinger thomaseizinger deleted the 2211-graceful-exit branch April 26, 2020 06:11
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.

Investigate e2e test error worker process has failed to exit gracefully
3 participants