5
votes

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.

1
It's been a while, but pretty sure that fixed it. - Valevalorin

1 Answers

6
votes

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.