Skip to content

Commit

Permalink
test(test_shared): be more patient with slow deletion operations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cfm authored and legoktm committed Feb 12, 2024
1 parent 69ad99c commit 947ffcc
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions client/tests/sdk/test_shared.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import os
import time

import pytest

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 947ffcc

Please sign in to comment.