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

Kill forked processes after tests are done #134

Merged
merged 1 commit into from
Nov 5, 2015
Merged

Conversation

vadimdemedes
Copy link
Contributor

@jamestalmage here's the refactored solution to the issue you mentioned - https://github.com/sindresorhus/ava/pull/134/files#diff-a48173105195b7a6481a3ad85b45144eR27.

The "trick" is to kill the forked process after the test results are received and not let cli.js handle this mess.

@jamestalmage
Copy link
Contributor

That works. My thought was to leave long running processes alone until we were all done (that's why I did it the way I did). Looking back, I can't remember why I thought that was important. If prematurely killing the process for test-file-a.js adversely affects test-file-b.js, you are doing something wrong anyway.

vadimdemedes pushed a commit that referenced this pull request Nov 5, 2015
Kill forked processes after tests are done
@vadimdemedes vadimdemedes merged commit 1d565e4 into master Nov 5, 2015
@vadimdemedes vadimdemedes deleted the fork-cleanup branch November 5, 2015 21:26
@jamestalmage
Copy link
Contributor

Oh wait - this is not going to work.

You need to do something like this:

// fork.js
new Promise(resolve, reject) {
  var storedResult;
  ps.on('result', function (result) {
    // don't resolve here we MUST wait for the process to exit.
    storedResult = result;
    ps.kill();
  });
  ps.on('exit', function(code) {
    if (code > 0) {
      reject();
    }
    else {
      resolve(storedResult);
   }
  });
}

@vadimdemedes
Copy link
Contributor Author

Why do we need to wait for the process to exit? results event is being sent after all tests are done.

@jamestalmage
Copy link
Contributor

Because then this: https://github.com/sindresorhus/ava/pull/134/files#diff-2cce40143051e25f811b56c79d619bf5R161

Gets executed before all the child processes finish exiting.

If you kill the parent, the child processes are killed without warning, despite where they may be wrapping up the kill signal that was sent to the child process.

nyc intercepts the kill signal, and delays letting the process actually die until it is done writing coverage results back to disk.

@vadimdemedes
Copy link
Contributor Author

Ok, I'll push an update, thanks for the tip!

@jamestalmage
Copy link
Contributor

@vdemedes
OK, I was working on a PR as well.
See #135.
It has a good failing test.
I can carry that through with the fix or let you handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants