mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.51k stars 2.99k forks source link

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

Open ReDemoNBR opened 4 days ago

ReDemoNBR commented 4 days ago

Bug Report Checklist

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 commented 4 days ago

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 commented 4 days ago

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! 🤎

ReDemoNBR commented 4 days ago

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