Ecto 2.0, concurrent acceptance tests, and channels

I’ve upgraded an Phoenix 1.1.4 app to use Ecto 2.0 and wanted to try adding acceptance tests before upgrading to 1.2. I followed the instructions in the Wallaby repo and got concurrent tests going with the Phoenix.Ecto.SQL.Sandbox plug. However I’ve run into a problem I’m not sure how to solve other than by switching back to sequential tests.

The page my acceptance tests loads connects to a channel (UserChannel), and in the authorized? function there I query the database as part of authorisation. This triggers a ** (RuntimeError) cannot find ownership process for #PID<>. I assume this is because of the way the the process handling the channel is started?

The web request and the websocket request both have the extra metadata in the UA string that phoenix_ecto uses to allow them access to the connection but I don’t see how to pass this through to the created channel processes.

My app starts or finds a named GenServer when a channel is joined, and that also talks to the database to manage state. Is there a way I can add this process to the ones allowed access to the connection too?

For now I’ve set async: false and put the Repo into shared mode.

1 Like

Check out this issue:

I thnk this works in the way that there’s a plug that shares the connection used in test with the one used in request handlers. But Phoenix handles the requests in different processes (and even different process subtree) than channels. So the ownership is not extended automatically to any other processes.

This is an issue not only with channels, but also with any other processes you may spawn on your own. Like background workers, email sending stuff etc. So yeah, it will not be suitable for everyone, but can be useful in many cases where you do not use channels/other processes.

1 Like