|
5 | 5 | [clojure.test :as t :refer [is are deftest testing]] |
6 | 6 | #_[cognitect.transit :as transit] |
7 | 7 | [datascript.core :as d] |
| 8 | + [datascript.db :as db] |
8 | 9 | [datascript.storage :as storage] |
9 | 10 | #_[datascript.test.core :as tdc])) |
10 | 11 |
|
|
139 | 140 | (is (= 8 (count @(:*writes storage))))))) ;; root, tail + 3 leves * 2 indexes |
140 | 141 | )) |
141 | 142 |
|
| 143 | +(deftest test-db-with-tail |
| 144 | + (testing "db-with-tail retracts stale cardinality/one values when replaying tail datoms" |
| 145 | + (let [schema {:block/updated-at {:db/index true}} |
| 146 | + db (-> (d/empty-db schema) |
| 147 | + (d/db-with [[:db/add 1 :block/updated-at 2]])) |
| 148 | + tail [[(db/datom 1 :block/updated-at 1772979060646 536870915 true)] |
| 149 | + [(db/datom 1 :block/updated-at 1772979061145 536870916 true)]] |
| 150 | + db' (storage/db-with-tail db tail)] |
| 151 | + (is (= [1772979061145] |
| 152 | + (mapv :v (d/datoms db' :avet :block/updated-at)))))) |
| 153 | + |
| 154 | + (testing "restore replays stored tail without leaving stale cardinality/one values" |
| 155 | + (let [schema {:block/updated-at {:db/index true}} |
| 156 | + storage (make-storage {:stats true}) |
| 157 | + db (-> (d/empty-db schema {:storage storage |
| 158 | + :branching-factor 32 |
| 159 | + :ref-type :strong}) |
| 160 | + (d/db-with [[:db/add 1 :block/updated-at 2]])) |
| 161 | + tail [[(db/datom 1 :block/updated-at 1772979060646 536870915 true)] |
| 162 | + [(db/datom 1 :block/updated-at 1772979061145 536870916 true)]]] |
| 163 | + (d/store db) |
| 164 | + (storage/store-tail db tail) |
| 165 | + (is (= [1772979061145] |
| 166 | + (mapv :v (d/datoms (d/restore storage) :avet :block/updated-at))))))) |
| 167 | + |
142 | 168 | ;; Commented out test-gc test-file-storage tests and helpers b/c they are not implemented in cljs |
143 | 169 |
|
144 | 170 | ;; (defmacro with-dir [dir & body] |
|
0 commit comments