Skip to content

Commit c7c216b

Browse files
Task: Stabilize Recording Test Timings (#147)
* Sleep recording test to prevent timing failures. * Increase sleep timing for calls. * Add contingency retries for cleanup.
1 parent a2bf75d commit c7c216b

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

test/integration/test_calls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def setUp(self):
9595
self.testCallId = "Call-Id"
9696
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>'
9797
self.callIdArray = []
98-
self.TEST_SLEEP = 3
98+
self.TEST_SLEEP = 5
9999
self.TEST_SLEEP_LONG = 15
100100

101101
def tearDown(self):
@@ -373,4 +373,4 @@ def test_update_call_bxml_not_found(self):
373373
self.assertApiException(context, NotFoundException, 404)
374374

375375
if __name__ == '__main__':
376-
unittest.main()
376+
unittest.main()

test/integration/test_recordings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ def test_successful_update_active_recording(self) -> None:
342342
# Make sure the call is alive
343343
assert_that(call_status['status'], equal_to('ALIVE'))
344344

345+
# Add a sleep to prevent timing issues
346+
time.sleep(TEST_SLEEP)
347+
345348
# Update the call to pause the recording
346349
update_call_recording = UpdateCallRecording(RecordingStateEnum('paused'))
347350
update_response = self.recordings_api_instance.update_call_recording_state(BW_ACCOUNT_ID, call_id, update_call_recording, _return_http_data_only=False)

test/utils/call_cleanup.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import time
2+
from bandwidth.exceptions import NotFoundException
13
from test.utils.env_variables import *
24
from bandwidth.model.call_state import CallState
35
from bandwidth.model.call_state_enum import CallStateEnum
46
from bandwidth.model.update_call import UpdateCall
57

8+
TEST_SLEEP = 3
9+
MAX_RETRIES = 10
10+
611
def callCleanup(self):
712
"""
813
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):
1520

1621
if len(self.callIdArray) > 0:
1722
for callId in self.callIdArray:
23+
retries = 1
24+
repeat = True
1825
body = UpdateCall(state=CallStateEnum("completed"))
19-
get_call_response: CallState = self.calls_api_instance.get_call_state(BW_ACCOUNT_ID, callId, _return_http_data_only=False)
20-
if get_call_response[0].state == 'active':
21-
self.calls_api_instance.update_call(BW_ACCOUNT_ID, callId, body, _return_http_data_only=False)
22-
elif get_call_response[0].state == 'complete':
23-
self.callIdArray.remove(callId)
26+
27+
while (repeat and retries <= MAX_RETRIES):
28+
try:
29+
get_call_response: CallState = self.calls_api_instance.get_call_state(BW_ACCOUNT_ID, callId, _return_http_data_only=False)
30+
if get_call_response[0].state == 'active':
31+
self.calls_api_instance.update_call(BW_ACCOUNT_ID, callId, body, _return_http_data_only=False)
32+
elif get_call_response[0].state == 'complete':
33+
self.callIdArray.remove(callId)
34+
35+
# We succeeded, break the loop
36+
repeat = False
37+
except NotFoundException:
38+
retries += 1
39+
print(f"Call ID was not registered, trying again attempt {retries}")
40+
time.sleep(TEST_SLEEP)
41+
2442
self.callIdArray.clear()
25-
pass
43+
pass

0 commit comments

Comments
 (0)