Skip to content

🐛 Bug: Unable to terminate long running tests #3570

Description

@segrey

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

Unable to terminate tests manually, e.g via Ctrl+C when running tests in a terminal.

Steps to Reproduce

  1. Create
it('should run 10 seconds', function (done) {
  setTimeout(done, 10000);
});
  1. Run with mocha --timeout 1000000 test.js
  2. Do not wait until the test finishes and press Ctrl+C to terminate it.

Expected behavior: The test is terminated.

Actual behavior: The test is still running.

Reproduces how often: Always

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 5.2.0 and 5.2.0
  • The output of node --version: v10.13.0
  • The version and architecture of your operating system: Linux 64-bit, 3.19.0-32-generic
  • Your shell (bash, zsh, PowerShell, cmd, etc.): bash
  • Your browser and version (if running browser tests):
  • Any other third party Mocha related modules (with versions):
  • The code transpiler being used:

Additional Information

Activity

  1. plroebuck commented on Nov 14, 2018

    @plroebuck
    Contributor

    WOMM...

    $ bin/_mocha --timeout 1000000 /tmp/test.js; echo $?
    ^C
    130
    $

    OS: macOS 10.13.6
    Node: v10.13.0
    Mocha: 5.2.0 (cfb1182) # modified trunk version, but changes unrelated to your issue

  2. segrey commented on Nov 14, 2018

    @segrey
    ContributorAuthor

    @plroebuck Please run it with time:

    time ./node_modules/mocha/bin/_mocha --timeout 10000000 test.js ; echo $?
    
    
    ^C  ✓ should run 10 seconds (10010ms)
    
      1 passing (10s)
    
    
    real	0m10.107s
    user	0m0.084s
    sys	0m0.020s
    130
    
  3. segrey commented on Nov 14, 2018

    @segrey
    ContributorAuthor

    The problem is that the test is terminated after 10 seconds, not right after Ctrl+C pressed.
    Looks like it's caused by

    mocha/bin/_mocha

    Lines 645 to 652 in a371e2f

    process.on('SIGINT', () => {
    runner.abort();
    // This is a hack:
    // Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT)
    // The amount of failures will be emitted as error code later
    runner.failures = 130;
    });

  4. plroebuck commented on Nov 14, 2018

    @plroebuck
    Contributor

    That portion of code only handles setting the exit code for SIGINT (aka <Ctrl-C>).

    $ time bin/_mocha --timeout 1000000 /tmp/test.js; echo $?
    ^C
    
    real	0m1.989s
    user	0m0.116s
    sys	0m0.042s
    130
    $
  5. segrey commented on Nov 15, 2018

    @segrey
    ContributorAuthor

    @plroebuck How can I checkout your mocha version?

    $ git checkout cfb1182c172e43effa3011f4ab620e4935f621e9
    fatal: reference is not a tree: cfb1182c172e43effa3011f4ab620e4935f621e9
    

    Same issue on Mac for me

    $ sw_vers
    ProductName:	Mac OS X
    ProductVersion:	10.14.1
    BuildVersion:	18B75
    
    $ node --version
    v10.13.0
    $ ./node_modules/mocha/bin/_mocha --version
    5.2.0
    $ time ./node_modules/mocha/bin/_mocha --timeout 1000000 /tmp/test.js ; echo $?
    
    
    ^C^C^C  ✓ should run 10 seconds (10005ms)
    
      1 passing (10s)
    
    
    real	0m10.151s
    user	0m0.122s
    sys	0m0.025s
    130
    

    Could you please try to repro using mocha 5.2.0 from npm?

  6. outsideris commented on Nov 19, 2018

    @outsideris
    Contributor

    In my local with d60b333 , I can reproduce it.

    time bin/_mocha --timeout 1000000 test.js ; echo $?
    
    
    ^C  ✓ should run 10 seconds (10004ms)
    
      1 passing (10s)
    
    
    real	0m10.199s
    user	0m0.178s
    sys	0m0.036s
    130
    
    time bin/mocha --timeout 1000000 test.js ; echo $?
    hfoehfoe
    
    
    ^CTerminated: 15
    
    real	0m0.606s
    user	0m0.228s
    sys	0m0.050s
    143
    
    $ sw_vers
    ProductName:	Mac OS X
    ProductVersion:	10.14.1
    BuildVersion:	18B75
    
    $ node -v
    v10.11.0
    
    $ ./bin/mocha --version
    5.2.0
    
  7. segrey commented on Dec 5, 2018

    @segrey
    ContributorAuthor

    @outsideris Thanks for confirming. Right, bin/_mocha should be used, not bin/mocha, I wasn't clear enough about it in the description.

    Guys, any idea on ideal SIGINT handling? Maybe something like: on the first SIGINT received, keep the current behavior, and if test is still running after N seconds (say N=2), disable SIGINT handler and resend SIGINT?

  8. added
    type: buga defect, confirmed by a maintainer
    area: usabilityconcerning user experience or interface
    and removed
    status: waiting for authorwaiting on response from OP or other posters - more information needed
    on Dec 5, 2018
  9. 30 remaining items

  10. added a commit that references this issue on Sep 12, 2019
  11. changed the title [-]Unable to terminate long running tests[/-] [+]🐛 Bug: Unable to terminate long running tests[/+] on Dec 27, 2023
  12. JoshuaKGoldberg commented on Feb 6, 2024

    @JoshuaKGoldberg
    Member

    I don't reproduce this - so looks like #3556 did fix it! Yay! 🎉

    If anybody is still seeing this bug, please do file a new issue with one of our new issue templates. They'll prompt for the info we'd need to re-triage. Cheers all! 🤎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificarea: usabilityconcerning user experience or interfacetype: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions