-
Notifications
You must be signed in to change notification settings - Fork 65
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
CreateTestContext doesn't get assigned different ports when run in parrallel #1326
Comments
I had a similar problem here #1085 See this stackoverflow issue for more info |
I dug into this issue and added some traces to monkey debug what is going on under the hood with get-port. I am using my plugins-prisma-and-jwt-auth-and-shield-piecemeal example for those that want a tests case. Clearly others have seen the need for some caching mechanism for some time as well:
Additionally, there are some loose ends, as illustrated by this comment by @jasonkuhrt which reference the issue #758; currently closed. While my efforts may be fruitless, I'm currently experimenting with refactoring this code to use a Singleton or an Object Pool. |
Update: Singletons and Object Pools are complete dead-ends due to Jest running each test suite in a separate process. There seem to be few options for sharing data between processes, and using Redis or other Shared-Memory libraries seems like a huge hack. The core issue appears to be related to the long duration it can take between port number assignment, the time it takes for the DevAppRunner to be created in createDevAppRunner, and the port actually being used when Amazingly, @luhagel random generated ports is extremely effective and can be paired with get-port to avoid used system ports.
Just for comparison, here are the performance improvements I see by doing these minor tweaks to Nexus/test. Original code with
|
- port workaround allows more performant parallel testing - testing on CI environments should still utilize Jest’s `—runInBand` flag - resolves prisma-labs#1326
- port workaround allows more performant parallel testing - testing on CI environments should still utilize Jest’s `—runInBand` flag - resolves prisma-labs#1326
- port workaround allows more performant parallel testing - testing on CI environments should still utilize Jest’s `—runInBand` flag
- during testing, get-port often re-uses the same port, due to the delay between when a free-port is assigned to a test, and when the port is actually used. Simply supplying an initial random port value to get-port dramatically reduces the chance of a port being used multiple times in a test run. - testing on CI environments should still utilize Jest’s `—runInBand` flag
- during testing, get-port often re-uses the same port, due to the delay between when a free-port is assigned to a test, and when the port is actually used. Simply supplying an initial random port value to get-port dramatically reduces the chance of a port being used multiple times in a test run. - testing on CI environments should still utilize Jest’s `—runInBand` flag
Screenshot
Description
get-port
currently suffers from an issue preventing the assignment of a new port when the initial one is already taken.This leads to tests erroring out because
Workaround
Right now tests have to be either
--runInBand
or the nexus has to be patched to assignMath.floor(Math.random() * (6000 - 4000)) + 4000
instead, which is ironically more reliable and works at least most of the time.The text was updated successfully, but these errors were encountered: