Skip to content

Commit

Permalink
Test that repeated ingest with UUIDv5 + direct works
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 18, 2023
1 parent 4015b07 commit ab886c8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from lsst.daf.butler import (
Config,
DataCoordinate,
DatasetIdGenEnum,
DatasetRef,
DatasetRefURIs,
DatasetType,
Expand Down Expand Up @@ -1101,6 +1102,36 @@ def testChecksum(self) -> None:
infos = datastore.getStoredItemsInfo(ref)
self.assertIsNotNone(infos[0].checksum)

def test_repeat_ingest(self):
"""Test that repeatedly ingesting the same file in direct mode
is allowed.
Test can only run with FileDatastore since that is the only one
supporting "direct" ingest.
"""
metrics, v4ref = self._prepareIngestTest()
datastore = self.makeDatastore()
v5ref = DatasetRef(
v4ref.datasetType, v4ref.dataId, v4ref.run, id_generation_mode=DatasetIdGenEnum.DATAID_TYPE_RUN
)

with lsst.utils.tests.getTempFilePath(".yaml", expectOutput=True) as path:
with open(path, "w") as fd:
yaml.dump(metrics._asdict(), stream=fd)

datastore.ingest(FileDataset(path=path, refs=v4ref), transfer="direct")

# This will fail because the ref is not using UUIDv4.
with self.assertRaises(RuntimeError):
datastore.ingest(FileDataset(path=path, refs=v4ref), transfer="direct")

# UUIDv5 can be repeatedly ingested in direct mode.
datastore.ingest(FileDataset(path=path, refs=v5ref), transfer="direct")
datastore.ingest(FileDataset(path=path, refs=v5ref), transfer="direct")

with self.assertRaises(RuntimeError):
datastore.ingest(FileDataset(path=path, refs=v5ref), transfer="copy")


class TrashDatastoreTestCase(PosixDatastoreTestCase):
"""Restrict trash test to FileDatastore."""
Expand Down

0 comments on commit ab886c8

Please sign in to comment.