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

test: make sigint test to actually check child pid #1656

Merged
merged 1 commit into from Jan 22, 2020

Conversation

axxie
Copy link
Contributor

@axxie axxie commented Dec 30, 2019

The aim of this PR is to fix some issues in SIGINT test.

The problem

Due to combination of the following effects, the SIGINT test does not actually test what it is made for:

  1. The callback of string.replace method takes the child pid from incorrect parameter:
    output: function (data) {
    if (match(data, 'pid: ')) {
    data.replace(/pid: (\d+)/, function (m) {
    childPID = m;
    });
    }
    },

    According to MDN, the first parameter contains entire substring, not the first capture group. As the result, the childPID contains string, not just number (“pid: 1234”).
  2. The test application ignores SIGINT signal and keeps hanging indefinitely:
    process.on('SIGINT', function() {
    // do nothing here
    });

    In fact, you can see it in the process list after running tests even if all tests pass.
  3. However, the check for child not being running after nodemon exit incorrectly succeeds:
    try {
    process.kill(childPID, 0);
    assert(false, 'child is still running at ' + childPID);
    } catch (e) {
    assert(true, 'child process was not running');
    }

    This happens because childPID is string and process.kill requires number and throws an exception. Due to exception, the test code assumes the child is not running and test passes.

Tested on:

  • nodemon: 2.0.2 (from sources in master)
  • node -v: v12.14.0
  • Operating system/terminal environment: Ubuntu 18.04.3 LTS

The fix

I implemented the following fixes:

  1. Changed the test application to only ignore the SIGINT if --dont-exit parameter is passed. In all other cases it exits upon receiving SIGINT as any normal application would do.
  2. Fixed the parsing of the child pid from the string
  3. Implemented more precise checking of the running process
  4. Split the test into two: one with child exiting on SIGINT (fast) and another one with child hanging and nodemon still exiting after 10 seconds.

@stale
Copy link

stale bot commented Jan 15, 2020

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Jan 15, 2020
@axxie
Copy link
Contributor Author

axxie commented Jan 16, 2020

Actually, this is just a preparation for another fix, for more serious issue.
This one is still an issue.

@stale stale bot removed the stale no activity for 2 weeks label Jan 16, 2020
@remy remy changed the title fix: make sigint test to actually check child pid test: make sigint test to actually check child pid Jan 22, 2020
@remy remy merged commit c279760 into remy:master Jan 22, 2020
@axxie axxie deleted the fix-sigint-test branch January 26, 2020 06:03
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.

None yet

2 participants