Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir/Plug/Phoenix: Calling halt doesn't stop downstream plugs from getting invoked during test

If I start up an instance of my phoenix app and hit it with requests, my plugs will halt appropriately. However, doing the same in a test environment, halt doesn't stop plugs downstream from being invoked which causes my tests to fail. I think the issue might come from the way I'm invoking the router during my test. Here's the helper function I'm using that is heavily borrowed from a similar function in the phoenix framework itself:

def call(router, verb, path, params \\ nil, headers \\ []) do
    add_headers(conn(verb, path, params), headers)
    |> Plug.Conn.fetch_params
    |> Plug.Parsers.call(parsers: [Plug.Parsers.JSON],
                    pass: ["*/*"],
                    json_decoder: Poison)
    |> router.call(router.init([]))
  end

Any ideas as to why calling my router like this causes halting to stop working?

EDIT: So I'm upgrading to Phoenix 0.13.1 in order to use their new endpoint testing module instead of the helper I rolled. I'll report back as to whether this fixes the issue or not.

like image 721
Valevalorin Avatar asked Jun 04 '15 16:06

Valevalorin


1 Answers

halt only works inside the plug pipeline. If you are manually piping then you would need to manually check for halt.

Honestly, I would drop your current pipeline and just invoke the actual endpoint from your tests. The endpoint pipeline is very fast, you shouldn't see any slow down really.

like image 157
José Valim Avatar answered Oct 21 '22 20:10

José Valim