Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: Stabilize Recording Test Timings #147

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/integration/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setUp(self):
self.testCallId = "Call-Id"
self.testBxmlBody = '<?xml version="1.0" encoding="UTF-8"?><Bxml><SpeakSentence locale="en_US" gender="female" voice="susan">This is a test bxml response</SpeakSentence><Pause duration="3"/></Bxml>'
self.callIdArray = []
self.TEST_SLEEP = 3
self.TEST_SLEEP = 5
self.TEST_SLEEP_LONG = 15

def tearDown(self):
Expand Down Expand Up @@ -373,4 +373,4 @@ def test_update_call_bxml_not_found(self):
self.assertApiException(context, NotFoundException, 404)

if __name__ == '__main__':
unittest.main()
unittest.main()
3 changes: 3 additions & 0 deletions test/integration/test_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 24 additions & 6 deletions test/utils/call_cleanup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
pass