Fl4m3Ph03n1x

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 n line by line.
  • When reaching the last line (Manager.login(credentials, false), I do not execute it with n or c. Instead I manually type the command Manager.login(credentials, false).
  • The call to bypass is made
  • Then I press c and 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

  1. Why is the bypass being called when I invoke Manager.login manually using the --breakpoint option and not when mix test runs?
  2. How can I fix my test?

Showing Posts 1 to 2

RudManusachi

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/2 makes its way to send the message?

I’d try to synchronize the test and Bypass with something like:

test "logs in user correctly", %{bypass: bypass, credentials: credentials} do
  test_pid = self()

  Bypass.expect_once(bypass, fn conn ->
    IO.inspect(conn.request_path, label: "REQ PATH")
    IO.inspect(conn.method, label: "METHOD")
  
    send(test_pid, :logging_in)
    
    Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
  end)
  
  _manager_pid = start_link_supervised!(ManagerSupervisor)
  Manager.login(credentials, false)

  # this ensures that the test will not exit until the message is received
  # (or until the default `assert_receive` timeout 100ms)
  assert_receive :logging_in
end
Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

Turns out that was the reason of the failure.
By using assert_receive(:login, 50000) I am able to have bypass receive the call.

The weird thing is that I tried it before, perhaps not with the correct timeout. Thanks for the help!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews