-
Notifications
You must be signed in to change notification settings - Fork 350
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
Tesla.Mock not compatible with Tesla.Middleware.Timeout #157
Comments
This is definitely a bug, thanks for reporting! About the
Nevertheless, the issue with timeout & mock is valid and needs to be somehow fixed. |
@stefanchrobot I would actually prefer option 1, personally. Option 2. makes following the behavior quite murky for no reason, and you actually really only need to fix the mock situation, after that you can capture other values from the test setup in the mock closure. Option 3. you can do already now, so there's no change needed, though it has the limitations that @teamon mentioned. |
Any news on this? Having the same problem with the timeout middleware when using the Mock. |
Having same problem with the timeout middleware when using Mock |
As you can read in #255, this issue is more complex than it seems.
|
Use tesla/lib/tesla/middleware/timeout.ex Lines 28 to 30 in 9c6d321
Swap the implementation with one that doesn't use |
@yordis even if the solution you propose will work but, I was thinking that an alternative solution could be using Something like this should be enough to find the process that contained the mocked data: pid = Enum.find(Process.get(:"$ancestors", []), nil, fn ancestor ->
!is_nil(Process.get(ancestor, :testa_mock))
end) Let me know if it makes sense and I could PR on this. |
PRs are always welcomed! |
Here it goes, dude! #668 |
Tesla.Mock
is not compatible with clients that use theTesla.Middleware.Timeout
middleware.The reason is that
Tesla.Mock
looks for the mock in the current process' dictionary and theTimeout
middleware runs the Tesla pipeline in a separateTask
to be able to terminate it on timeout.As a workaround, I'm going to disable the
Timeout
middleware in the test env, but this is kludgy. I'd rather have the mock support theTimeout
middleware.I see three ways to do this:
Timeout
middleware to copy the mock into theTask
's process dictionaryTimeout
middleware to keep the parent process pid in the process dictionary; theTesla.Mock.pdict_get()
will use that to look for the mock function in the parent's process dictionaryThe
mock
function would put the mock spec somewhere in the middlewares. Ideally, this would replace the current adapter with specced mock adapter - this has the added benefit that one no longer needs to set the:mock
adapter in tests.The last point would actually be great thing to do, since I have the following use case: I have a set of unit tests for my API module where I mock the adapter and verify it's behavior. But for all other tests I've built a fake implementation of the API which is started alongside the main app - this way the tests exercise the same code path as the production code. For that reason, I would strongly prefer solution 3.
Let me know which one works for you and I'll happily prepare a PR.
The text was updated successfully, but these errors were encountered: