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

🐛 Bug: this.parent.titlePath is not a function during parallel execution with retries #5170

Closed
3 of 4 tasks
ReDemoNBR opened this issue Jul 5, 2024 · 7 comments · Fixed by #5173
Closed
3 of 4 tasks
Assignees
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@ReDemoNBR
Copy link

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have '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, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

I expected to be able to run the test suites in parallel mode using ./bin/mocha --parallel <test/files> without failure in v10.6.0

Actual

The tests are failing with:

1) Uncaught error outside test suite:
     Uncaught TypeError: this.parent.titlePath is not a function
      at Array.forEach (<anonymous>)

With --full-trace CLI option, it shows (I snipped the project name)

1) Uncaught error outside test suite:
     Uncaught TypeError: this.parent.titlePath is not a function
      at Runnable.titlePath (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/runnable.js:217:22)
      at Runnable.fullTitle (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/runnable.js:206:15)
      at Test.serialize (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/test.js:94:23)
      at SerializableEvent.serialize (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/serializer.js:256:27)
      at /home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/serializer.js:72:13
      at Array.forEach (<anonymous>)
      at SerializableWorkerResult.serialize (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/serializer.js:71:17)
      at serialize (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/serializer.js:366:15)
      at /home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/worker.js:127:28
      at ParallelBuffered.done (/home/rdn/Projects/<snipped>/node_modules/mocha/lib/nodejs/reporters/parallel-buffered.js:151:5)

Note that I tested this multiple times in 10.4.0 and 10.5.1 versions and I could not reproduce even after exhaustive attempts.

Minimal, Reproducible Example

I was not able to find 100% reproducible steps in my local machine, as it is not giving me consistent behavior, failing around 40% of the time in different test suites.
However in our CI environment (6 vCPU + 16GB RAM machines) it is failing at all times when using 6 parallel jobs, in different test suites.

So I could not find a specific code to trigger it

Versions

Versions:

$ mocha --version
bash: mocha: command not found
$ npx mocha --version
10.6.0
$ node_modules/.bin/mocha --version
10.6.0
$ node --version
v22.4.0

Shell: Bash (5.2.026-5) (ArchLinux)

Related modules: JS with ESModules

Additional Info

During my own debugging of the mocha v10.6.0 directly installed in node_modules, I was able to add some debugging info and found that at this line, this.parent is actually a string with value "[Circular]" (without quotes), thus failing when trying to access the function this.parent.titlePath().

I could not find the error in v10.4.0 or v10.5.1 (I did not test v10.5.0)

@ReDemoNBR ReDemoNBR added status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer labels Jul 5, 2024
@ReDemoNBR
Copy link
Author

I didnt want to speculate in the OG issue (so we could delete this comment if that is against CoC), but I compared the changes from 10.4.0 to 10.6.0 and I squint my eyes when I look at this code added on 10.6.0 which seems very hard to test

@JoshuaKGoldberg
Copy link
Member

cc @sam-super @voxpelli from that PR.

I believe you that this bug exists, but without a reproduction, there's really not much we can do to fix it 😞. @ReDemoNBR we'd be happy to sign an NDA if that'd help getting readonly access to your CI logs and project setup. Marking as waiting for more info in the meantime.

Thanks for trying out the latest Mocha & filing! 🤎

@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author waiting on response from OP - more information needed and removed status: in triage a maintainer should (re-)triage (review) this issue labels Jul 5, 2024
@ReDemoNBR
Copy link
Author

Even though the project is not open source, the company is open source friendly so no NDA is needed, just your word should be enough

For more info that I can give here, there are 308 test suites with 1115 tests in total.

To be honest, there is not much logs in GitLab CI as the --full-trace is not enabled (risk of full error tracing printing credentials or secrets), but I can try to record it myself and send it your way along with the full CI logs (about 2k lines each run), or schedule a meeting where I can screenshare and do it live (walk you through it, do some more debugging etc) in my Brazilian timezone (UTC-0300).
I'd be happy to help

You may contact me in private using the email address in my profile

@Marcus-Karl
Copy link

Marcus-Karl commented Jul 10, 2024

My team has been encountering this issue.
I have found that mocha 10.5.1 works, but 10.5.2 returns the error.

Using mocha 10.5.2:

package.json

{
  "name": "testing",
  "version": "1.0.0",
  "description": "Test Scripts",
  "license": "UNLICENSED",
  "devDependencies": {
    "chai": "4.4.1",
    "mocha": "10.5.2"
  }
}

.mocharc.json

{
  "diff": true,
  "parallel": true,
  "extension": ["js"],
  "package": "./package.json",
  "timeout": "60000",
  "retries": 1
}

test-file.js

const { expect } = require('chai');

describe(`Test File`, () => {
  it(`Test`, async () => {
    expect(1).to.equal(2);
  });
});

command: npx mocha .\test-file.js

Result:

1) Uncaught error outside test suite

  0 passing (321ms)
  1 failing

  1) Uncaught error outside test suite:
     Uncaught TypeError: this.parent.titlePath is not a function
      at Array.forEach (<anonymous>)

If I switch mocha to 10.5.1 I get:

  Test File
    1) Test


  0 passing (323ms)
  1 failing

  1) Test File
       Test:

      AssertionError: expected 1 to equal 2
      + expected - actual

      -1
      +2

      at Context.<anonymous> (test-file.js:5:18)
      at process.processImmediate (node:internal/timers:478:21)

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! and removed status: waiting for author waiting on response from OP - more information needed labels Jul 10, 2024
@JoshuaKGoldberg
Copy link
Member

Note also #5032 (comment):

  1) Uncaught error outside test suite:
     Uncaught TypeError: this.parent.titlePath is not a function
      at Test.Runnable.titlePath (/node_modules/mocha/lib/runnable.js:217:22)
      at Test.Runnable.fullTitle (/node_modules/mocha/lib/runnable.js:206:15)
      at Test.serialize (/node_modules/mocha/lib/test.js:94:23)
      at SerializableEvent.serialize (/node_modules/mocha/lib/nodejs/serializer.js:256:27)
      at /node_modules/mocha/lib/nodejs/serializer.js:72:13
      at Array.forEach (<anonymous>)
      at SerializableWorkerResult.serialize (/node_modules/mocha/lib/nodejs/serializer.js:71:17)
      at serialize (/node_modules/mocha/lib/nodejs/serializer.js:366:15)
      at /node_modules/mocha/lib/nodejs/worker.js:127:28
      at ParallelBuffered.done (/node_modules/mocha/lib/nodejs/reporters/parallel-buffered.js:151:5)

@JoshuaKGoldberg
Copy link
Member

I see the issue, and will send a PR soon. Thanks for posting everyone! Seeing the different inputs on how this could happen was very useful. 🙂

@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Jul 10, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title 🐛 Bug: this.parent.titlePath is not a function during parallel execution 🐛 Bug: this.parent.titlePath is not a function during parallel execution with retries Jul 11, 2024
@ReDemoNBR
Copy link
Author

I tested #5173 (review) in my project and it worked.
Basically I made a .patch file with the diff and applied in CI with patch -u node_modules/mocha/lib/nodejs/serializer.js -i mocha.patch before running the tests.

[email protected]

2024-07-11 00 28 22 gitlab com 5fcb8945380a

[email protected] + patch from PR #5173 applied

2024-07-11 00 28 35 gitlab com 7fe1e12cd841

delatrie added a commit to allure-framework/allure-js that referenced this issue Aug 9, 2024
May update again as soon as mochajs/mocha#5170 is released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants