From 032bfafec226869b3153ce7dc358b66363c49455 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Thu, 13 Oct 2016 14:24:49 -0700 Subject: [PATCH] Review comment: fail pending transactions after closing connection. This is pretty difficult to test robustly, but here's a stab at it. --- src/common/datomish/transact.cljc | 54 ++++++++++++++++++++----------- test/datomish/transact_test.cljc | 36 +++++++++++++++++++++ 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/common/datomish/transact.cljc b/src/common/datomish/transact.cljc index 04c56e69..3c369ba7 100644 --- a/src/common/datomish/transact.cljc +++ b/src/common/datomish/transact.cljc @@ -50,12 +50,18 @@ (defrecord Connection [closed? current-db transact-chan] IConnection (close [conn] - (if (compare-and-set! (:closed? conn) false true) - (do - ;; This immediately stops ! token-chan (gensym "transactor-token")) (loop [] (when-let [token ( (! (:listener-source conn) report)) - report)))] + (case sentinel + :sentinel-close + ;; Time to close the underlying DB. + ( (! (:listener-source conn) report)) + report)))))] ;; Even when report is nil (transaction not committed), pair is non-nil. (>! result pair)) (>! token-chan token) diff --git a/test/datomish/transact_test.cljc b/test/datomish/transact_test.cljc index ed211711..732e1a7c 100644 --- a/test/datomish/transact_test.cljc +++ b/test/datomish/transact_test.cljc @@ -242,4 +242,40 @@ ;; Closing a closed connection is a no-op. ( (count xs) 0)) + (is (> (count es) 0)) + (is (= {:error :transact/connection-closed} (ex-data e)))))) + (finally + ;; Closing a closed connection is a no-op. + (