Skip to content

Commit

Permalink
[GH-1433] No TDR temporary snapshots in tests (#595)
Browse files Browse the repository at this point in the history
Instead, we can rely on temporary datasets which automatically delete any of their snapshots before the dataset.
  • Loading branch information
okotsopoulos committed Mar 24, 2022
1 parent 2f36927 commit 8cbaf75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
23 changes: 12 additions & 11 deletions api/test/wfl/integration/datarepo_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@
(is (== 1 (count row-ids))
"Single input row should have been written to the dataset")
(testing "creating snapshot after completed ingest"
(fixtures/with-temporary-snapshot
(snapshots/unique-snapshot-request tdr-profile
dataset
table-name
row-ids)
#(let [snapshot (datarepo/snapshot %)
expected-prefix (str (:name dataset) "_" table-name)]
(is (= % (:id snapshot)))
(is (str/starts-with? (:name snapshot) expected-prefix)
(str "Snapshot name should start with "
"dataset name and table name"))))))))))))
(let [request (snapshots/unique-snapshot-request
tdr-profile
dataset
table-name
row-ids)
snapshot-id (datarepo/create-snapshot request)
snapshot (datarepo/snapshot snapshot-id)
expected-prefix (str (:name dataset) "_" table-name)]
(is (= snapshot-id (:id snapshot)))
(is (str/starts-with? (:name snapshot) expected-prefix)
(str "Snapshot name should start with "
"dataset name and table name")))))))))))

(deftest test-flattened-query-result
(let [samplesheets (-> (datarepo/snapshot (:id testing-snapshot))
Expand Down
12 changes: 0 additions & 12 deletions api/test/wfl/tools/fixtures.clj
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,6 @@
datarepo/delete-snapshots-then-dataset
f))

;; Recommendation: only call this within a temporary dataset.
;; If calling within a fixed dataset, running the same test concurrently
;; may fail due to exclusive dataset locking on snapshot deletion.
;;
(defn with-temporary-snapshot
"Create a temporary Terra Data Repository Snapshot with `snapshot-request`"
[snapshot-request f]
(util/bracket
#(datarepo/create-snapshot snapshot-request)
datarepo/delete-snapshot
f))

(defn with-temporary-workspace
"Create and use a temporary Terra Workspace."
([workspace-prefix group f]
Expand Down

0 comments on commit 8cbaf75

Please sign in to comment.