Ava shared workers #3110
-
Hello Team, I'm trying out shared workers concept in ava. Idea here is to create hapijs server in shared worker and share that server uri across the test files. Here is the repro https://github.com/sathishsoundharajan/shared-workers When i'm trying to run 2 test files simultaneously only one of the test files stuck and it always fails |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
You're only registering the server after it's ready, which means there is a race condition if both test files request it. Instead write the promise to the map, and then await that for each request from the test files. Also, you'll want to use this with AVA 4 where the test files run in worker threads, rather than child processes, which should make it all a bit quicker. |
Beta Was this translation helpful? Give feedback.
-
Thank you @novemberborn
If i have understood wrongly from your feedback, please correct me, if possible can u give me small snippet ? |
Beta Was this translation helpful? Give feedback.
-
I also wanted to explain why i'm trying this POC more. My Node.js app which current uses Hapi.js framework has 3500+ test cases. In each test file we are trying to create hapi server ( without starting, just initializing it along with plugins ) and use the Our current Unit test suite runs for more than 1h 30 mins for each commit. We believe this is due to following reasons
For these reasons, to solve the first issue i thought of instead of requiring and initialising the app for test process, let's try to use the shared workers concept to create hapijs server once in main process and share that server to test-files. ( which i believe this will reduce test-files start up times ) For the second issue, i don't have any idea on how to solve it :) if anyone from the community able to provide some feedback will be helpful. |
Beta Was this translation helpful? Give feedback.
Thank you @novemberborn
I cannot upgrade to ava 4 because my Node.js version is stuck at v12.16.1 ( for UT alone i'm planning to run it in v12.17 because ava requires it )
Please correct me if i'm wrong, are you saying
await bootstrap()
function which actually starts the server and stores insidesharedContexts
map will have race condition if both test files are running simultaneously ? If that is the case based on your workaround provided by you i have to remove the await which surrounds thebootstrap()
function, but if i do that, i will run into these errorsError: #<Promise> could not be cloned
Server object cannot be cloned using zlib
Also if each test file awaits the server …