Timing issue after using `set_mox_global`
Nobody has claimed this yet.
- Dominant language
- Elixir
- Stars
- 1.4k
- Forks
- 79
- Avg merge
- 5h 18m
- Merged PRs (30d)
- 1
Description
I upgraded Mox from 1.1.0 to 1.2.0 and now have an intermittent problem.
I have two test files in a directory, the first of which sets Mox to global mode, and the second of which does not.
I've never had problems with these files before, but since upgrading to 1.2.0 the second file will sometimes now fail multiple tests with an error like:
** (ArgumentError) cannot add expectations/stubs to JitsiMeet.Token.JwtMock in the current process (#PID<0.1826.0>) because Mox is in global mode and the global process is #PID<0.1814.0>. Only the process that set Mox to global can set expectations/stubs in global mode
It's not consistent, but I would estimate it occurs on roughly 1/8 test runs. Looking at the code changes I would think this must have to do with NimbleOwnership.allow having a timeout. I didn't look farther than seeing that. I would think that the setting of the global mode should end when the test module exits, (i.e. from an on_exit function), not based on a timeout.
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]
Elixir 1.14.5 (compiled with Erlang/OTP 26)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the intermittent failures using the two test files described in the issue, then inspect NimbleOwnership.allow and the timeout-based handling of Mox global mode. Compare that lifecycle with the proposed on_exit behavior; done means the second test file no longer inherits global mode and the affected tests pass reliably across repeated runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100