lud

lud

Force full crash of Bandit in case of error

Hello,

In our tests we are mocking http servers to assert different things about sent http requests. This is the child spec that we use:

      Supervisor.child_spec(
        {Bandit,
         plug: {MockablePlug, spec},
         scheme: :http,
         port: 0,
         thousand_island_options: [num_acceptors: 10, num_connections: 2]},
        id: {__MODULE__, spec.id}
      )

There is nothing notable about MockablePlug except that it rescues exceptions to log different things, and then reraises them.

We use that spec with start_link_supervised! in order to fail our test if our ad-hoc http server fails. The problem we face is that there is a layer of supervision that prevents our test from failing.

I would like to know if there is a builtin mechanism to force the whole Bandit instance to crash when the http handler does. I understand that this is the opposite of what we would generally want so I would not be surprised if there is not.

The handlers seem to be dynamically started so I cannot manually link it to the test process before calling it.

Thank you :slight_smile:

(pinging @mtrudel )

First Post!

LostKobrakai

LostKobrakai

Crashing an individual handler is generally not meant to propagate to the whole server, so this behavior probably expected.

I guess you could register a telemetry handler to catch handlers crashing from exceptions.

Last Post!

lud

lud

Yeah I see the logged errors, plus the fact that I rescue and log useful informations before re-raising helps, but the test still passes, and that is really the problem.

The plug receives the pid of the test, passed as options from the setup of all of that, but even if I link the plug process to the test process, it does not fail the test (unless I sleep in the test for a couple milliseconds) because the test terminates too fast.

The easiest thing I do right now is send a message from the plug process to the test process after all the assert(), and the test uses assert_received to it can fail. It works but it’s annoying. I’m trying Bypass for the new test I’m working on, it seems to properly handle my case (which is really: I can’t fail the production code by returning something wrong from the mock plug, as the production code does not care about the http response, so I can only fail from the plug handler).

Thanks anyway, and thanks for Bandit, it works great :slight_smile:

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement