Pubsub isolation in tests

I have a Phoenix application which has LiveView tests. When i run the tests in async mode the broadcasts from one test can interfere with other tests. What is the best way to handle this? Scenario: * Test 1 opens a live connection to a live_view which listens to broadcasts on a Ash resource * Test 2 performs an update on an object of the same resource. This causes a broadcast message because I've setup PubSub broadcasting on the resource * Test 1 now gets the broadcast update and crashes because it can't find that object The tests are already isolated through Postgres transactions. I was wondering if there was something similar for the PubSub server?
3 Replies
ZachDaniel
ZachDaniel•3d ago
Good question. I could swear I've solved this elsewhere 😅 since in tests we disable async, we could solve some (but not all) of these cases by supporting a flag in the process dictionary that tells us to only broadcast to self Like Process.get(:pubsub_test?)
Rutgerdj
RutgerdjOP•3d ago
So there's not really a standard way to do this? Like starting a separate PubSub server per test or something? I guess until there's a good solution i can just run the tests synchronous
ZachDaniel
ZachDaniel•3d ago
Yeah, I think often the reason its not so much of an issue is that topics are scoped to some piece of data that shouldn't exist in other tests

Did you find this page helpful?