Replace crypto-hash with a custom hashing function in tests #9986
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 betweencrypto-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):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 ofcrypto-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 replacecrypto-hash
with our own simple function that doesn't use worker threads. This commit does just that by introducing a super simple customsha256
function that leverages Nodecrypto
, and uses it instead.Fixes #9982