-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fix unstable behavior without async: false
#126
Conversation
Since Meck mocks globally, I added a process/module (MockLock) that controls access to this resource. Now, before ExVCR.Mock.mock_methods calls :meck.expect, it request a lock from MockLock. When the lock becomes available, MockLock sends :lock_granted to the calling process. When the calling process is done, it calls ExVCR.MockLock.release_lock(). Right before MockLock sends :lock_granted to calling process, it starts to monitor the process. If the calling process goes down, MockLock will be notified and release the lock. I also had to make ExVCR.Setting work with async. In order to achieve this, I used the same pattern for naming the ets table as in ExVCR.Adapter.Hackney.Store, which is to include the pid in the ets table name. This does introduce a breaking change: calling ExVCR.Config functions outside of test process, such as in setup_all, will not work. Instead, ExVCR.Config should be called in setup or test. I have documented this in the README Notes section. Another change is that I removed the clear_mock option. Now, :meck.unload is called for each test every time. This is necessary for MockLock/async to work correctly.
1 similar comment
@parroty have you had a chance to look at this? I'm also interested in having this for my team. |
Thanks for the extensive implementation! I'll be pushing. |
Is it possible this broke how |
@andrewtimberlake This change did bring about a breaking change that calling ExVCR.Config functions from outside the test process will not work (such as within You should still be able to call |
@parroty I don't think that this was a suitable change for a minor version bump. The readme prior to this PR had multiple examples that used
|
I did have the config in |
Since Meck mocks globally, I added a process/module (MockLock) that
controls access to this resource. Now, before ExVCR.Mock.mock_methods calls
:meck.expect, it request a lock from MockLock. When the lock becomes available,
MockLock sends :lock_granted to the calling process. When the calling process is
done, it calls ExVCR.MockLock.release_lock(). Right before MockLock sends
:lock_granted to calling process, it starts to monitor the process. If the
calling process goes down, MockLock will be notified and release the lock.
I also had to make ExVCR.Setting work with async. In order to achieve
this, I used the same pattern for naming the ets table as in
ExVCR.Adapter.Hackney.Store, which is to include the pid in the ets
table name. This does introduce a breaking change: calling ExVCR.Config
functions outside of test process, such as in setup_all, will not work.
Instead, ExVCR.Config should be called in setup or test. I have
documented this in the README Notes section.
Another change is that I removed the clear_mock option. Now,
:meck.unload is called for each test every time. This is necessary for
MockLock/async to work correctly.