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

add failing test demonstrating long running onExit() hook in child process #135

Closed

Conversation

jamestalmage
Copy link
Contributor

RE: #134

@jamestalmage jamestalmage force-pushed the refix-forked-process-kill branch from 20d109b to 5c17496 Compare November 5, 2015 22:30
@vadimdemedes
Copy link
Contributor

I assume this is safe to close since #136 is in master?

@jamestalmage
Copy link
Contributor Author

I would prefer to see it merged.
It provides a test that mimics the nyc issue and confirms the previous commits are actually doing what we want.

@jamestalmage
Copy link
Contributor Author

despite the branch name, it does not actually fix anything (you beat me to the punch on that).

it's just a test

@vadimdemedes
Copy link
Contributor

I think this test is kind of complicating it, since we already have a test for this. What situation does this test checks?

@vadimdemedes
Copy link
Contributor

Just not understanding the purpose completely. Could you please explain?

@jamestalmage
Copy link
Contributor Author

So,

The existing test covers making sure we force close some process that is being kept open due to a perpetual process (i.e. Firebase, express, etc). If that is all that is going on, then the process should exit immediately in once it receives the kill signal (no delay).

That's the setTimeout(15 seconds) in the long-running-test, and then an assertion that we DON'T wait for that setTimeout to finish.

The other scenario is when we send a kill signal to the process, and it intentionally intercepts and delays closure of the process. This is the case with nyc. Nyc specifically uses signal-exit to intercept the kill signal and delay the exit until it is done writing to disk. signal-exit only accepts synchronous callbacks. (I am guessing this is a safety measure to make sure you don't screw things up with a complicated async exit process, and fail to ever let the process exit). This is the the onExit portion.

I run through a 2 second loop

var start = Date.now()
while (Date.now() - start > 2000) {} // just waiting 2 seconds synchronously because I have to be synchronous inside onExit
process.send({..delay-completed-event...})

Before all our changes we were exiting the parent and killing the child before the delay-completed-event. Even though we fixed the problem, I realized my initial test actually didn't cover the full scenario.

I agree, it's not a super straightforward test, but I am simulating a rather convoluted process and I don't know how to make it simpler.


fork(fixture('long-running.js'))
.on('exit', function () {
t.ok(Date.now() - start < 10000);
t.ok(Date.now() - start < 10000, 'did NOT wait for setTimeout(fn, 15000');
t.ok(cleanupCompleted, 'did wait for onExit(fn) to complete');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these assertion messages are bad. I should fix them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are error messages, they are displayed when assertion fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, race condition :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right - I've got them in the affirmative ('did NOT wait for setTimeout(fn, 15000')') -that is actually what we want (do not wait 15 seconds).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamestalmage I've added Windows testing with AppVeyor and this assertion fails: https://ci.appveyor.com/project/sindresorhus/ava/build/2/job/w7efao2if7n2g2q9 Could you take a look?

@vadimdemedes
Copy link
Contributor

Ok, let's see what @sindresorhus thinks.

@sindresorhus
Copy link
Member

👍

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.

3 participants