From 7b05356bd0bb66b912f369571972c3dec5fc5710 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Mon, 15 Sep 2025 17:47:31 -0500 Subject: [PATCH] test: do not create timestamp collision unnecessarily Change-Id: Ib6bf702e38495e52e3b2f5ca95ed17c519018474 Signed-off-by: Clay Gerrard --- test/unit/obj/test_auditor.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py index 276a16227b..6892829fa9 100644 --- a/test/unit/obj/test_auditor.py +++ b/test/unit/obj/test_auditor.py @@ -170,6 +170,10 @@ class TestAuditorBase(BaseTestCase): @patch_policies(_mocked_policies) class TestAuditor(TestAuditorBase): + def setUp(self): + super().setUp() + self.ts = make_timestamp_iter() + def test_worker_conf_parms(self): def check_common_defaults(): self.assertEqual(auditor_worker.max_bytes_per_second, 10000000) @@ -320,18 +324,18 @@ class TestAuditor(TestAuditorBase): self.rcache, self.devices) data = b'0' * 1024 etag = md5(usedforsecurity=False) - timestamp = str(normalize_timestamp(time.time())) + timestamp = next(self.ts) with self.disk_file.create() as writer: writer.write(data) etag.update(data) etag = etag.hexdigest() metadata = { 'ETag': etag, - 'X-Timestamp': timestamp, + 'X-Timestamp': timestamp.normal, 'Content-Length': str(os.fstat(writer._fd).st_size), } writer.put(metadata) - writer.commit(Timestamp(timestamp)) + writer.commit(timestamp) pre_quarantines = auditor_worker.quarantines # remake so it will have metadata @@ -343,12 +347,14 @@ class TestAuditor(TestAuditorBase): policy=POLICIES.legacy)) self.assertEqual(auditor_worker.quarantines, pre_quarantines) etag = md5(b'1' + b'0' * 1023, usedforsecurity=False).hexdigest() + ts2 = next(self.ts) metadata['ETag'] = etag + metadata['X-Timestamp'] = ts2.normal with self.disk_file.create() as writer: writer.write(data) writer.put(metadata) - writer.commit(Timestamp(timestamp)) + writer.commit(ts2) auditor_worker.object_audit( AuditLocation(self.disk_file._datadir, 'sda', '0', @@ -671,7 +677,7 @@ class TestAuditor(TestAuditorBase): auditor_worker = auditor.AuditorWorker(self.conf, self.logger, self.rcache, self.devices) auditor_worker.log_time = 0 - timestamp = str(normalize_timestamp(time.time())) + timestamp = next(self.ts) pre_quarantines = auditor_worker.quarantines data = b'0' * 1024 @@ -680,11 +686,11 @@ class TestAuditor(TestAuditorBase): writer.write(data) metadata = { 'ETag': md5(data, usedforsecurity=False).hexdigest(), - 'X-Timestamp': timestamp, + 'X-Timestamp': timestamp.normal, 'Content-Length': str(os.fstat(writer._fd).st_size), } writer.put(metadata) - writer.commit(Timestamp(timestamp)) + writer.commit(timestamp) # policy 0 write_file(self.disk_file) @@ -700,17 +706,18 @@ class TestAuditor(TestAuditorBase): self.assertEqual(auditor_worker.stats_buckets[10240], 0) # pick up some additional code coverage, large file + ts2 = next(self.ts) data = b'0' * 1024 * 1024 for df in (self.disk_file, self.disk_file_ec): with df.create() as writer: writer.write(data) metadata = { 'ETag': md5(data, usedforsecurity=False).hexdigest(), - 'X-Timestamp': timestamp, + 'X-Timestamp': ts2.normal, 'Content-Length': str(os.fstat(writer._fd).st_size), } writer.put(metadata) - writer.commit(Timestamp(timestamp)) + writer.commit(ts2) auditor_worker.audit_all_objects(device_dirs=['sda', 'sdb']) self.assertEqual(auditor_worker.quarantines, pre_quarantines) # still have the 1024 byte object left in policy-1 (plus the