This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-07
Channels
- # aleph (4)
- # announcements (9)
- # babashka (44)
- # beginners (6)
- # cider (8)
- # clj-kondo (5)
- # clojars (10)
- # clojure (10)
- # clojure-berlin (1)
- # clojure-dev (9)
- # clojure-europe (20)
- # clojure-gamedev (1)
- # clojure-miami (2)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (5)
- # clojurescript (12)
- # conjure (1)
- # cursive (19)
- # data-science (2)
- # datahike (10)
- # etaoin (5)
- # events (3)
- # fulcro (14)
- # gratitude (2)
- # honeysql (8)
- # humbleui (1)
- # hyperfiddle (60)
- # introduce-yourself (7)
- # jobs-discuss (27)
- # juxt (2)
- # kaocha (7)
- # lsp (23)
- # malli (9)
- # missionary (2)
- # off-topic (48)
- # pathom (24)
- # releases (1)
- # shadow-cljs (256)
- # sql (46)
- # xtdb (19)
Invoking the following test through the terminal, the process does not exit:
(ns test
(:require
[xtdb.api :as xt]
[clojure.test :refer :all]))
(def node (xt/start-node {}))
(deftest foo (is (= 1 1)))
This is with XT 1.24.3
. Is this expected behaviour?
I imagine one needs to .close
the node, but naively appending (.close node)
to that file throws java.lang.IllegalStateException: TxLog is closed.
which I guess makes sense.
For more context, I'd like to submit the tx a single time, then run many tests over that node. Using fixtures would help with that, but the issue remains if I require a ns that has an XT node started in it. Is there a simple way out? 🙂The not simple way out: lift starting the node from the ns containing XT logic, so I could require it in tests.
yep, you've got it, the node will need to be closed. we usually either go for test fixtures, as you say, or if all the references to the node are within a certain scope, a with-open
in your case, sounds like a :once
fixture to start up and tear down the node should do the trick?
(def ^:dynamic *node* nil)
(t/use-fixtures :once
(fn [f]
(with-open [node (xt/start-node {})]
(xt/submit-tx node ...)
(binding [*node* node]
(f)))))
?Not if I have a foo.xt-logic
that does (def node (xt/start-node {}))
and then I require it in the test ns.
It would be nice to have a workaround, though. E.g. to support using hyperfiddle/rcf tests throughout the ns. (https://clojurians.slack.com/archives/C7Q9GSHFV/p1706818329319899, same issue.) It works fine at the REPL, so maybe that's enough.
fair, yep - something like integrant/integrant.repl, perhaps, to manage the lifecycle? :thinking_face:
Only have a server and XTDB, so I'm resisting adding more perhaps unnecessary complexity 🙂
This might be convenient at the REPL (as long as you run the tests manually or through rcf
) and it exits properly:
(ns test
(:require
[xtdb.api :as xt]
[clojure.test :refer :all]
[hyperfiddle.rcf :refer [tests]]))
(def node (xt/start-node {}))
(xt/submit-tx node [[::xt/put {:xt/id 1}]])
(xt/sync node)
(use-fixtures :once
(fn [t]
(t)
(.close node)))
(deftest bar
(is (= (xt/entity (xt/db node) 1)
{:xt/id 1})))
(tests
(xt/entity (xt/db node) 1) := {:xt/id 1})
I'm going to reinforce the "poor hygiene" aspect and note that top-level content in namespaces (`def` and other non-`defn` expressions) should never have any side-effects -- those things happen when you load a namespace, so they'll happen if any tooling loads your namespace to analyze it or if you try to compile the namespace. It really is a good practice to adopt to always put side-effects into functions so you can control when they happen.
Thanks for jumping in, Sean! Spurred on by your comment (James was too gentle 😁), I took the time to clean this up. I also accepted that not all tests can/should be 'inlined'. (This was in turn inspired by some of Sean's arguments I found online.)