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

Coverage file writing hook is called too early during 'exit'. #11445

Closed
Fishrock123 opened this issue Feb 17, 2017 · 1 comment
Closed

Coverage file writing hook is called too early during 'exit'. #11445

Fishrock123 opened this issue Feb 17, 2017 · 1 comment
Labels
build Issues and PRs related to build files or the CI. test Issues and PRs related to the tests.

Comments

@Fishrock123
Copy link
Contributor

It has come to my attention while I was looking through coverage.nodejs.org that my commit intended to add coverage of a specific if branch in process.nextTick() was still now showing up in in the coverage reports.

The commit is f65a48f and the relevant lines can be found at

// on the way out, don't bother. it won't get fired anyway.
if (process._exiting)
return;
.

It appears that in the coverage setup, the exit handler is added too early (that is, before test code is able to attach exit handlers (or at least in all possible cases)):

function setup() {
const reallyReallyExit = process.reallyExit;
process.reallyExit = function(code) {
writeCoverage();
reallyReallyExit(code);
};
process.on('exit', writeCoverage);
}

I tried to patch this a couple ways but I wasn't able to figure out the ideal way to make this exit listener always fire last without adding a new C++ hook.

Here is a diff that I think should work, but just appears to make things worse:

diff --git a/lib/internal/process/write-coverage.js b/lib/internal/process/write-coverage.js
index 6bbc59a..be06a5e 100644
--- a/lib/internal/process/write-coverage.js
+++ b/lib/internal/process/write-coverage.js
@@ -40,7 +40,11 @@ function setup() {
     reallyReallyExit(code);
   };
 
-  process.on('exit', writeCoverage);
+  process.on('exit', () => {
+    process.on('exit', () => {
+      process.on('exit', writeCoverage);
+    });
+  });
 }
 
 exports.setup = setup;

Refs: #10856

cc @CurryKitten, @mhdawson, @addaleax

@Fishrock123 Fishrock123 added build Issues and PRs related to build files or the CI. test Issues and PRs related to the tests. labels Feb 17, 2017
@addaleax
Copy link
Member

Have you tried just dropping the isWritingCoverage guards? That might do the trick, and I’m not a hundred percent sure whether that is actually necessary for anything…

Fishrock123 added a commit to Fishrock123/node that referenced this issue Mar 24, 2017
MylesBorins pushed a commit that referenced this issue Mar 28, 2017
PR-URL: #12023
Fixes: #11445
Refs: f65a48f
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants