Description
Based on this discussion it'd be great to have a teardown method within the shared worker. E.g. after negotiating the protocol, you can call .teardown()
to register a callback.
Under normal use, after a test run, AVA can explicitly message the shared workers to begin their teardown. They must then respond when complete. The worker may then exit on its own or be terminated explicitly.
In watch mode, AVA should keep the workers alive until it's made to exit. It should then tear down the workers gracefully, as per above.
We should no longer unreference the worker:
ava/lib/plugin-support/shared-workers.js
Line 115 in bdf2cf0
Looking at this now, the whole deregistration bit here makes no sense:
ava/lib/plugin-support/shared-workers.js
Lines 54 to 58 in bdf2cf0
The shared worker may end up in a "deregistered" state if ever there is a gap between test workers using it.
The API instance should probably track shared worker instances, not in a per-run variable like now, but on the instance itself. This will require some rewiring:
Line 236 in bdf2cf0
Then, perhaps, we could add a teardown()
method to the API itself, which we can call after its run completes:
Line 467 in bdf2cf0
Watch mode requires the process to be "killed" using a SIGINT
signal. This is currently handled internally be the API instance:
Line 55 in d742672
And then per run:
Line 96 in d742672
It might make more sense to register for SIGINT
in the lib/cli.js
file and then call an interrupt()
method on the API instance, after which we can kick off the teardown.
When SIGINT
is received a second time we should forcibly exit the process, without waiting for a graceful teardown of the shared workers.