diff --git a/test/integration/test_calls.py b/test/integration/test_calls.py index 220e1ca7..19984e05 100644 --- a/test/integration/test_calls.py +++ b/test/integration/test_calls.py @@ -95,7 +95,7 @@ def setUp(self): self.testCallId = "Call-Id" self.testBxmlBody = 'This is a test bxml response' self.callIdArray = [] - self.TEST_SLEEP = 3 + self.TEST_SLEEP = 5 self.TEST_SLEEP_LONG = 15 def tearDown(self): @@ -373,4 +373,4 @@ def test_update_call_bxml_not_found(self): self.assertApiException(context, NotFoundException, 404) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/test/integration/test_recordings.py b/test/integration/test_recordings.py index dd0fd5c6..b8eabd99 100644 --- a/test/integration/test_recordings.py +++ b/test/integration/test_recordings.py @@ -342,6 +342,9 @@ def test_successful_update_active_recording(self) -> None: # Make sure the call is alive assert_that(call_status['status'], equal_to('ALIVE')) + # Add a sleep to prevent timing issues + time.sleep(TEST_SLEEP) + # Update the call to pause the recording update_call_recording = UpdateCallRecording(RecordingStateEnum('paused')) update_response = self.recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, call_id, update_call_recording, _return_http_data_only=False) diff --git a/test/utils/call_cleanup.py b/test/utils/call_cleanup.py index d9c0cf98..d63f38b6 100644 --- a/test/utils/call_cleanup.py +++ b/test/utils/call_cleanup.py @@ -1,8 +1,13 @@ +import time +from bandwidth.exceptions import NotFoundException from test.utils.env_variables import * from bandwidth.model.call_state import CallState from bandwidth.model.call_state_enum import CallStateEnum from bandwidth.model.update_call import UpdateCall +TEST_SLEEP = 3 +MAX_RETRIES = 10 + def callCleanup(self): """ Whenever we create an actual call, we'll add the call_id to the callIdArray. Then when the integration test is done, as part of tearDown we'll: @@ -15,11 +20,24 @@ def callCleanup(self): if len(self.callIdArray) > 0: for callId in self.callIdArray: + retries = 1 + repeat = True body = UpdateCall(state=CallStateEnum("completed")) - get_call_response: CallState = self.calls_api_instance.get_call_state(BW_ACCOUNT_ID, callId, _return_http_data_only=False) - if get_call_response[0].state == 'active': - self.calls_api_instance.update_call(BW_ACCOUNT_ID, callId, body, _return_http_data_only=False) - elif get_call_response[0].state == 'complete': - self.callIdArray.remove(callId) + + while (repeat and retries <= MAX_RETRIES): + try: + get_call_response: CallState = self.calls_api_instance.get_call_state(BW_ACCOUNT_ID, callId, _return_http_data_only=False) + if get_call_response[0].state == 'active': + self.calls_api_instance.update_call(BW_ACCOUNT_ID, callId, body, _return_http_data_only=False) + elif get_call_response[0].state == 'complete': + self.callIdArray.remove(callId) + + # We succeeded, break the loop + repeat = False + except NotFoundException: + retries += 1 + print(f"Call ID was not registered, trying again attempt {retries}") + time.sleep(TEST_SLEEP) + self.callIdArray.clear() - pass \ No newline at end of file + pass