← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ikoruk/launchpad:fix-tenacity into launchpad:master

 

Yuliy Schwartzburg has proposed merging ~ikoruk/launchpad:fix-tenacity into launchpad:master.

Commit message:
Fix tenacity tests to go with current tenacity 9.0.0 api

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ikoruk/launchpad/+git/launchpad/+merge/477213
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ikoruk/launchpad:fix-tenacity into launchpad:master.
diff --git a/lib/lp/oci/tests/test_ociregistryclient.py b/lib/lp/oci/tests/test_ociregistryclient.py
index 6d01ea9..8fff5b9 100644
--- a/lib/lp/oci/tests/test_ociregistryclient.py
+++ b/lib/lp/oci/tests/test_ociregistryclient.py
@@ -16,6 +16,7 @@ from http.client import IncompleteRead
 from unittest import mock
 
 import responses
+from tenacity import wait_fixed
 import transaction
 from fixtures import MockPatch
 from requests.exceptions import ConnectionError, HTTPError
@@ -693,26 +694,25 @@ class TestOCIRegistryClient(
         )
         # Patch sleep so we don't need to change our arguments and the
         # test is instant
-        self.client._upload.retry.sleep = lambda x: None
-
-        try:
-            push_rule = self.build.recipe.push_rules[0]
-            self.client._upload(
-                "test-digest",
-                push_rule,
-                None,
-                0,
-                RegistryHTTPClient(push_rule),
-            )
-        except retry_type:
-            # Check that tenacity and our counting agree
-            self.assertEqual(
-                5, self.client._upload.retry.statistics["attempt_number"]
-            )
-            self.assertEqual(5, self.retry_count)
-        except Exception:
-            # We should see the original exception, not a RetryError
-            raise
+        with mock.patch.object(self.client._upload.retry, "wait", wait_fixed(0)):
+            try:
+                push_rule = self.build.recipe.push_rules[0]
+                self.client._upload(
+                    "test-digest",
+                    push_rule,
+                    None,
+                    0,
+                    RegistryHTTPClient(push_rule),
+                )
+            except retry_type:
+                # Check that tenacity and our counting agree
+                self.assertEqual(
+                    5, self.client._upload.statistics["attempt_number"]
+                )
+                self.assertEqual(5, self.retry_count)
+            except Exception:
+                # We should see the original exception, not a RetryError
+                raise
 
     def test_upload_retries_exception(self):
         # Use a separate counting mechanism so we're not entirely relying