Fork me on GitHub

I'm writing unit tests for a Clojure namespace that will use Crux for storage. I've written a ":once" test fixture that starts and stops a standalone in-memory Crux instance. In order to write order independent unit tests I'd like to write an ":each" test fixture that clears all of the data out of the Crux instance before starting a test.


How do I clear all of the data out of a Crux instance?


Hi @U44P1CP5K 🙂 I would expect that if you have managed to "stop" the in-memory instance then it should naturally be cleared of any data (due to GC) before you restart it. Is that not the case? Can you describe how you're stopping & starting in more detail please? Feel free to post a snippet/gist


I believe you're correct. I was trying to avoid stopping it because starting it takes a few seconds. A few seconds per test will make running all the tests very slow.


Ah okay. There may be a mechanism available to start nodes more quickly after the first time. The test suites use a lot of temporary test fixtures (including in-memory), e.g. I'll check with the team in the morning to see if there are any tricks to suggest


Is there a query that will return all the entities in the node?


{:find [e]
 :where [[e :crux.db/id _]]}


Of course. Thanks!


🙂 you're welcome


maybe there's something like with in datomic? I.e. "return a view of the database in-memory as if this transaction was applied"?


@U0MKRS1FX we are definitely seeing valid use-cases for providing an equivalent with capability (e.g. testing invariants in transaction functions, and queries over "unconfirmed" transactions) but it doesn't exist right now and it's not completely trivial to add. This is a good reminder to open an issue about it though 💡




Have you considered making your test-suite just ignore old data and create new data for the current test? Every so often it can still be useful to completely delete the test database or all the data in it but I've found this to be a useful technique when working with systems in which it is difficult to delete data (e.g. kafka).