From 947ffcca76c60980f47f52998b8937520f00a59e Mon Sep 17 00:00:00 2001 From: Cory Francis Myers Date: Wed, 31 Jan 2024 16:54:52 -0800 Subject: [PATCH] test(test_shared): be more patient with slow deletion operations I'd want to DRY up this logic if this pattern shows up in more places, but it would require adding another level of indirection. A @retry decorator isn't appropriate at the level of the test method, and a context manager can't loop over its closure. --- client/tests/sdk/test_shared.py | 36 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/client/tests/sdk/test_shared.py b/client/tests/sdk/test_shared.py index c1f7a5a880..f26c0a32a7 100644 --- a/client/tests/sdk/test_shared.py +++ b/client/tests/sdk/test_shared.py @@ -1,5 +1,6 @@ import datetime import os +import time import pytest @@ -37,11 +38,20 @@ def delete_conversation(self): self.api.delete_conversation(s.uuid) - submissions = self.api.get_submissions(s) - assert 0 == len(submissions) - - replies = self.api.get_replies_from_source(s) - assert 0 == len(replies) + attempts = 3 + while attempts >= 0: # Deletion is both non-blocking and slow. + attempts = attempts - 1 + try: + submissions = self.api.get_submissions(s) + assert 0 == len(submissions) + + replies = self.api.get_replies_from_source(s) + assert 0 == len(replies) + except AssertionError: + if attempts == 0: + raise + else: + time.sleep(5) def delete_source(self, from_string=False): number_of_sources_before = len(self.api.get_sources()) @@ -98,9 +108,19 @@ def delete_submission(self, from_string=False): else: subs = self.api.get_all_submissions() assert self.api.delete_submission(subs[0]) - new_subs = self.api.get_all_submissions() - # We now should have 1 less submission - assert len(new_subs) == number_of_submissions_before - 1 + + attempts = 3 + while attempts >= 0: # Deletion is both non-blocking and slow. + attempts = attempts - 1 + try: + new_subs = self.api.get_all_submissions() + # We now should have 1 less submission + assert len(new_subs) == number_of_submissions_before - 1 + except: + if attempts == 0: + raise + else: + time.sleep(5) # Let us make sure that sub[0] is not there for s in new_subs: