Fork me on GitHub
#xtdb
<
2024-04-02
>
jcd16:04:38

For testing against a postgres DB, I've seen people write a fixture that couches all calls in a test in the same transaction, and then rollback that transaction when the test is finished. It looks like https://v1-docs.xtdb.com/language-reference/1.24.3/datalog-transactions/#speculative-transactions could be used to do similar; is there syntax to not realize/rollback speculative transactions?

jarohen16:04:54

Hey @U023QRP1648 👋 We tend to use throwaway in-memory instances for this:

(with-open [xt (xt/start-node {})]
  ...)
or, as a fixture:
(def ^:dynamic *node*)

(t/use-fixtures :each
  (fn [f]
    (binding [*node* (xt/start-node {})]
      (f)))

jcd16:04:18

Awesome! Thanks, I'll noodle with that.

🙏 1
seancorfield16:04:46

My little usermanager (XTDB) example does that: a real DB for running the app, but an in-memory node for running tests. Seems to be a good pattern.

1
jcd16:04:34

Yea, it seems pretty elegant.