TestServer - No fuzz mocking of third-party services

I’ve been trying to replace Bypass + Mox with TestServer, and I really appreciate the simplification and ease of understanding it brought back to my tests :purple_heart:

The one case that’s been bugging me and preventing me from shipping it is how to handle a test involving Phoenix.Presence. As far as I understand, depending on timing/scheduling my test server gets hit with a different number of requests.

If I TestServer.add one too little I get a warning in the test output, even though the test passes:

warning: ** (RuntimeError) TestServer.Instance #PID<0.471.0> received an unexpected GET request at /v1/users/79e78660-718c-4f59-8e4c-51b61599d868

If I TestServer.add one too many, then the test fails:

(RuntimeError) TestServer.Instance #PID<0.465.0> did not receive a request for these routes before the test ended

Is there a blessed way in TestServer to say “this handler should match at least once (or N times)?”
Alternatively, any other ideas of what I could consider doing? Thanks!

1 Like