-
Notifications
You must be signed in to change notification settings - Fork 9
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
mocked modules are not returned to normal state when verify/1 returns #8
Comments
Thanks for reporting. I will try to reproduce this, then fix it. Do you have a failing minimal self contained test case? |
Unfortunately not. This seems to be a classical heisenbug. I have test modules with >20 test cases run fine on my local, fairly fast machine, as well as on our CI pipeline server, then suddenly either may act up. Sometimes a retry of the whole test suite works, sometimes not. I have just started to add these sleeps without further reflection, as I need the tests to run. |
Thanks for reporting, we use em for production code, too, and I know about heisenbugs in unit tests |
I still haven't figured it out, I will meet a guy tomorrow, who might be able to help... |
Thank you for staying on it. |
Ok, I can reproduce it now. |
Introduce the `em_mocking_queue' to serialize module mocking to prevent module loading races. The race condition is between checking if a module is already mocked and loading a mock module, such that it might happen that two processes both overwrite a module with a mock version.
I hope this finally fixes it... but since it is a Heisenbug, we'll have to see. |
Yes, it seems to do the trick. Many thanks for the great work. |
* Replace `em_mocking_queue` by `em_module_loader` * Discourage concurrent mocking * Fix the race condition introduced in 7.1.0 * Add `em:lock()' and `em:unlock()' to mark sections of code that would appreciate that no modules are mocked. * Hopefully fix #8
Oh well... still breaks our tests :/ Another version is on its way. |
Version 7.2.2 is out, and it should fix this. |
Hmm..no. I go lots of those after turning to 7.2.2. The test was running with 7.1.0:
|
Things worked after a fashion with 7.1.0. The only case where the mocked module was not released seem to be when;
where the module_c:stop/1 would call a function in module_b. If I wait a few hundred miliseconds before module_c:stop/1, it worked fine with 7.1.0. Yes, I could mock the last function to be called in module_b as well, but we have lot of bad tests, that will take some time to do. :( |
Ok ... I will try to make a test-case out of your example and then try to fix it, if it breaks... |
Sometime after the switch to gen_statem (it may be completelely unconnected to that change) I regularly get errors like the one below.
When inserting a timer:sleep(100) after the em:verify/1 in the previous test of my eunit suite all works fine. I have started to add a sleep after every verify to work around this.
I have had a look at the code, but cannot find a race condition (at least no according to the documentation of the Erlang API functions that are called by erlymock)
The text was updated successfully, but these errors were encountered: