How to test for specific DB failures?

Hi everyone,
for a specific use case I need to test a database error to verify the expected behavior.
Is there any suggestion you can give me on how to proceed?

Doesn’t Ecto.Adapters.SQL.html#query/4 work fine? It should not blow up and just give you an {:error, exception} value.

2 Likes

Can you expand on what sort of error you want to have happen?

It’s fairly heavy (and complicated), but the most accurate way I’ve seen people test this sort of thing is with tools like Toxiproxy.

You’d put the proxy in between the app and the database, and then send the proxy instructions about how to fail.

That’s not something that most applications would need, though, unless you’re doing very specialized things above-and-beyond standard Ecto.

1 Like