summaryrefslogtreecommitdiff
path: root/oslo_utils/tests/test_fileutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_utils/tests/test_fileutils.py')
-rw-r--r--oslo_utils/tests/test_fileutils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/oslo_utils/tests/test_fileutils.py b/oslo_utils/tests/test_fileutils.py
index d34a38b..7e089c8 100644
--- a/oslo_utils/tests/test_fileutils.py
+++ b/oslo_utils/tests/test_fileutils.py
@@ -19,6 +19,8 @@ import os
import shutil
import stat
import tempfile
+import time
+from unittest import mock
import uuid
from oslotest import base as test_base
@@ -215,6 +217,23 @@ class TestComputeFileChecksum(test_base.BaseTestCase):
self.assertEqual(expected_checksum.hexdigest(), actual_checksum)
+ def test_compute_checksum_sleep_0_called(self):
+ path = fileutils.write_to_tempfile(self.content)
+ self.assertTrue(os.path.exists(path))
+ self.check_file_content(self.content, path)
+
+ expected_checksum = hashlib.sha256()
+ expected_checksum.update(self.content)
+
+ with mock.patch.object(time, "sleep") as sleep_mock:
+ actual_checksum = fileutils.compute_file_checksum(
+ path, read_chunksize=4)
+
+ sleep_mock.assert_has_calls([mock.call(0)] * 3)
+ # Just to make sure that there were exactly 3 calls
+ self.assertEqual(3, sleep_mock.call_count)
+ self.assertEqual(expected_checksum.hexdigest(), actual_checksum)
+
def test_compute_checksum_named_algorithm(self):
path = fileutils.write_to_tempfile(self.content)
self.assertTrue(os.path.exists(path))