Test fixture persistence with NoSQL DBs in Phoenix and Ecto? (Unique constraint violations)

I’m using ArangoDB through the arangox_ecto package. I had to remove the ecto_sql package to get things to work properly. I’m still having trouble with the persistence of test fixtures, as they are not removed from the database between tests. This means that when another test tries to create the same test fixture, I get a unique constraint violation.

How can I fix this so that the fixtures are cleaned up properly, as happens with the SQL Sandbox adapter.

@TomGrozev if you see this I’d love your input.

Hi budgie, I have just seen this so sorry it took so long to respond. Give version 2.0.0 a go it supports running ecto_sql alongside arangox_ecto.

Is this the actual issue?

The OP needs to clear data between tests, which classically is done in postgres by doing the operations in a transaction and doing a rollback of it at the end of the test, it allows for easy async tests out of the box.

This obviously is a feature exclusive to postgres, for sqlite this behavior is done by actually removing all data at the end of the test, making the execution of tests in async mode impossible.

I’ve had success with async unit testing a NoSQL DB with Ecto by using a new tenant for each TestCase. The TestCase then deletes the tenant after the test execution. It works well if the db supports lightweight tenants. I’m not familiar with the features of ArangoDB though.

1 Like

Version 2.0 of arangox_ecto now includes a Sandbox like in ecto_sql so tests can be done in transactions which automatically rollback. Using this would resolve the test fixtures as it can be reset to a known state at the start of the tests.

1 Like