Fl4m3Ph03n1x
Background
I am trying to do an integration test for a simple terminal application that I am writting.
This application is basically a Supervisor, which supervises other smaller libraries.
The communication within the project is mostly asynchronous, with processes sending messages to callers.
Problem
One of the tests I make requires an HTTP request, so I decided to use bypass for this. However, the problem is rather surprising to me. Here is the test:
setup do
bypass = Bypass.open(port: 8082)
credentials = %{email: "an_email", pass: "a_password"}
%{
credentials: credentials,
bypass: bypass
}
end
test "logs in user correctly", %{bypass: bypass, credentials: credentials} do
Bypass.expect_once(bypass, fn conn ->
IO.inspect(conn.request_path, label: "REQ PATH")
IO.inspect(conn.method, label: "METHOD")
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
end)
# start the application
_manager_pid = start_link_supervised!(ManagerSupervisor)
# this should make a GET request to bypass but ...
Manager.login(credentials, false)
end
If I simply run mix test this simple test fails as Bypass received no requests.
1) test login logs in user correctly (Manager.WorkerTest)
test/integration/manager_test.exs:83
No HTTP request arrived at Bypass
Confusion
However, confunsingly enough, if I use the --breakpoints feature by running iex -S mix test --breakpoints I can make the test pass by doing some simple steps:
- Press
nline by line. - When reaching the last line (
Manager.login(credentials, false), I do not execute it withnorc. Instead I manually type the commandManager.login(credentials, false). - The call to
bypassis made - Then I press
cand the test passes
This is beyond confusing to me. It appears that the test process in not invoking Manager.login like it should.
I cannot explain this.
Questions
- Why is the
bypassbeing called when I invokeManager.loginmanually using the--breakpointoption and not whenmix testruns? - How can I fix my test?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
RudManusachi
Is it possible that when ran without breakpoints the test finishes before the process makes the call. While with breakpoints, by the time you press
c,Manage.login/2makes its way to send the message?I’d try to synchronize the test and Bypass with something like:
Fl4m3Ph03n1x
Turns out that was the reason of the failure.
By using
assert_receive(:login, 50000)I am able to havebypassreceive the call.The weird thing is that I tried it before, perhaps not with the correct timeout. Thanks for the help!