Fork me on GitHub
#xtdb
<
2020-01-27
>
hairfire20:01:10

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.

hairfire20:01:55

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

refset22:01:07

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

hairfire22:01:40

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.

refset22:01:13

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. https://github.com/juxt/crux/blob/master/crux-test/test/crux/node_test.clj#L58-L65 I'll check with the team in the morning to see if there are any tricks to suggest

hairfire22:01:04

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

refset22:01:54

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

hairfire22:01:31

Of course. Thanks!

refset22:01:43

🙂 you're welcome

augustl08:01:17

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

refset10:01:54

@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 💡

augustl10:01:08

:thumbsup:

cddr13:02:19

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).