From ee927d24de33581f49b47d5841e5076176631c67 Mon Sep 17 00:00:00 2001 From: matthewkmartin Date: Fri, 24 Feb 2023 10:56:51 -0500 Subject: [PATCH 1/3] Sleep recording test to prevent timing failures. --- test/integration/test_recordings.py | 3 +++ 1 file changed, 3 insertions(+) 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) From 0757be09eecf3ddb53f26deca49d028935ef9f8f Mon Sep 17 00:00:00 2001 From: matthewkmartin Date: Fri, 24 Feb 2023 11:10:24 -0500 Subject: [PATCH 2/3] Increase sleep timing for calls. --- test/integration/test_calls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() From b7443af2c9d9941b022cdcae59dbb1b86453c9e5 Mon Sep 17 00:00:00 2001 From: matthewkmartin Date: Fri, 24 Feb 2023 14:11:18 -0500 Subject: [PATCH 3/3] Add contingency retries for cleanup. --- test/utils/call_cleanup.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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