Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

File bif passthrough #36

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
4 participants
@ghost

ghost commented Aug 11, 2011

A deadlock occurs if meck is used to mock a module that is needed to recompile modules. The rough sequence of events causing the deadlock is the following when the file module is mocked:

1.  meck successfully loads a replacement for the file module ([unstick,passthrough])
2. add an expectation to the file module using meck:expect
3. a call is made to the file_meck server
4. the file_meck server updates the list of expecations
5. the file_meck server recompiles the replacement of the file module
5.1. during recompilation the previously loaded replacement module is used
5.2 all calls to the replacement module are redirected to the file_meck server
6. during recompilation a call is made to the file:get_cwd() function by a compiler worker.
7.  deadlock.

I resolved the issue by making a worker process responsible for executing recompliation and notifying the client when the module has been reloaded. In this case it enables the file_meck server to respond to calls
during this time.

Owner

eproxus commented Aug 15, 2011

I've also been aware some time that mocking the modules involved with compilation and code loading is troublesome, to say the least. :-) Great summary of what goes wrong.

I won't pull this in now for various reasons, the biggest being that I'm planning to (sometime) rewrite the code loading not to use the code module (instead using erlang:load_module/2, replicating some of the code module's features). This will most likely be a generic function in the meck_mod module.

@ghost

ghost commented Aug 15, 2011

I had no expectations that this to be merged in without any adjustments on my end. It's good to know that you've already got an alternative solution in mind. Feel free to close this pull request and track the issue elsewhere.

Owner

eproxus commented Aug 16, 2011

Would this be an acceptable test case for this use case?

passthrough_file_test_() ->
     ok = meck:new(file, [passthrough, unstick]),
     ok = meck:expect(file, new_func, 0, ok),
     ?assertEqual(ok, file:new_func()),
     ?assert(meck:validate(file)),
     ok = meck:unload(file).

I can trigger the deadlock calling basically any function in any module used by any module that meck is calling during reloading code (thus being inside the meck gen_server). The file module is the most obvious example.

@ghost

ghost commented Aug 16, 2011

I ran this test against the master where it failed and the file-bif-passthrough branch where it passed, only thing i would change is to remove the last underscore to confuse eunit less.

Owner

eproxus commented Aug 16, 2011

Ah, yes of course. ;-)

Hi, what is the status of this issue? I can still feel the pain with latest master version. Is there any work to be done that I could help with to fix this issue?

Mocking file:read_file will simplify some tests I want to write in a great deal ...

@ghost

ghost commented Apr 8, 2012

How ironic, resurrecting an issue from the dead during the Easter holidays.

+1 I'm also wondering what the status of this issue is. Never know when I'll have to mock the file module again.

Owner

eproxus commented Apr 11, 2012

I'll pull down this branch and test it again. Already now I can say that I'd like the compilation state (running / not running) inside the gen_server state instead of in the process dictionary...

Owner

eproxus commented Apr 12, 2012

@klaar I've rebased your branch onto master here: https://github.com/eproxus/meck/tree/support/klaar/file-bif-passthrough so you can get a feel for how the changes would merge onto the current master.

Unfortunately the /proc filesystem does not exist on OS X so the test fails. Is it possible to rewrite it to run locally inside the test folder so that it's portable? Can you rebase your branch onto my master again?

Owner

eproxus commented May 7, 2012

Any progress on this?

I hope you are not expecting anything from my side :)

DBarney commented Aug 28, 2012

I just ran into this as well. +1

Contributor

horkhe commented Sep 11, 2012

@eproxus I would like to take these changes, rebase them, and adjust the unit tests as per your comment. But I am not sure if I can add my commits to this pull request, so should I just create another pull request or what?

Owner

eproxus commented Sep 15, 2012

Please create a new pull request, this is way too far behind in commits. See if you can include the original commits so all authors can be attributed, otherwise include them in the commit message perhaps?

Contributor

horkhe commented Sep 15, 2012

@eproxus ok, will do

Contributor

horkhe commented Oct 23, 2012

You can peek at the result in my private repo under feature/file-bif-passthrough branch. It is base on the stub-all pull request and I will create a pull request for it as soon as the base is accepted.

Contributor

horkhe commented Nov 4, 2012

@eproxus now we can close this saying that it was fixed by pull request #82

Owner

eproxus commented Nov 4, 2012

@horkhe Ok, didn't see that this was merged together with the refactoring branch.

@eproxus eproxus closed this Nov 4, 2012

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