Postgrex.Notifications process doesn't receive notifications in tests

Or, at least, that’s what I think happens

https://github.com/idi-ot/notify_and_channels

I have a listener of NOTIFY messages from postgres, and even though in dev it works (see web readme), this test, which relies on the listener fails.

It sounds like your tests are using the SQL sandbox:

https://github.com/idi-ot/notify_and_channels/blob/master/apps/web/test/support/channel_case.ex#L30

so the test would happen inside a transaction which gets rolled back at the end. Since the transaction is never committed, the NOTIFY is not emitted either. You could create a new case based on ChannelCase that doesn’t have the sandbox setup code, so that your test actually commits to DB.

2 Likes

Used Ecto.Adapters.SQL.Sandbox.unboxed_run/2, seems to work for now.

Thank you!

Do you manually clean up after that test? If you don’t it will leave lingering data right?

2 Likes

Didn’t think of that. Yes, all the posts created during these unboxed tests are still in the test database. Will add some clean up phase now, thank you!

1 Like