Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace crypto-hash with a custom hashing function in tests #9986

Merged
merged 4 commits into from Aug 5, 2022

Conversation

hwillson
Copy link
Member

@hwillson hwillson commented Aug 5, 2022

It looks like some combination of the changes in #9928 and #9942 exposed a long running issue caused by using crypto-hash in our @apollo/client/link/persisted-queries tests. crypto-hash spawns a thread the first time it's called, and keeps that thread alive until the end of program execution, if worker threads are available (which they are for our tests since they're running in CI via Node). Unfortunately there appears to be some kind of a race condition between crypto-hash unrefing its worker and Jest reporting a successful test suite exit, which leads to Jest reporting the following (which is seen by running jest with the --detectOpenHandles setting enabled):

Jest has detected the following X open handles potentially keeping Jest from exiting:

This then appears to be leading to failed tests in CI.

We can look further into what's causing this race condition between crypto-hash and Jest, but just dropping the use of crypto-hash is likely a faster solution. We just need to verify that a hashing function can be successfully set and used with the persisted queries link, which means we can replace crypto-hash with our own simple function that doesn't use worker threads. This commit does just that by introducing a super simple custom sha256 function that leverages Node crypto, and uses it instead.

Fixes #9982

@hwillson hwillson marked this pull request as draft August 5, 2022 01:06
@hwillson
Copy link
Member Author

hwillson commented Aug 5, 2022

Note that this isn't ready for review yet - this fixes the Jest open handle issue but there is more to do.

@hwillson
Copy link
Member Author

hwillson commented Aug 5, 2022

Hmm - the initial changes in this PR fix one problem (that crypto-hash was keeping a worker thread open), but Jest is still hanging off and on. This appears to be caused by our new use of Jest's projects feature along with leveraging multiple Jest workers. Something is hanging and Jest can't properly exit because of it. Running all our of tests serially fixes the issue (using Jest's runInBand feature), but this slows our tests down a bit. Still, we might want to get this in for now to at least get our tests back to passing reliably. We can then continue to look into what's causing the hanging.

Another option is to keep the Jest workers enabled and forceExit Jest, but leaving whatever Jest is having a hard time with open could cause harder to troubleshoot tests errors in the future.

@hwillson hwillson marked this pull request as ready for review August 5, 2022 14:29
It looks like some combination of the changes in #9928 and #9942 exposed
a long running issue caused by using `crypto-hash` in our
`@apollo/client/link/persisted-queries` tests. `crypto-hash` spawns a
thread the first time it's called, and keeps that thread alive until the
end of program execution, if worker threads are available (which they are
for our tests since they're running in CI via Node). Unfortunately there
appears to be some kind of a race condition between `crypto-hash`
`unref`ing its worker and Jest reporting a successful test suite exit, which
leads to Jest reporting the following (which is seen by running jest with
the `--detectOpenHandles` setting enabled):

```
Jest has detected the following X open handles potentially keeping Jest from exiting:
```

This then appears to be leading to failed tests in CI.

We can look further into what's causing this race condition between
`crypto-hash` and Jest, but just dropping the use of `crypto-hash` is
likely a faster solution. We just need to verify that a hashing function can
be successfully set and used with the persisted queries link, which means we
can replace `crypto-hash` with our own simple function that doesn't use
worker threads. This commit does just that by introducing a super simple
custom `sha256` function that leverages Node `crypto`, and uses it
instead.

Fixes #9982
JEST_JUNIT_OUTPUT is no longer a valid jest-junit environment variable.
Force Jest to run all tests serially to debug process hanging.
@hwillson hwillson merged commit 2a3467d into main Aug 5, 2022
@hwillson hwillson deleted the issue-9982 branch August 5, 2022 20:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
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 testing timeouts on CI
2 participants