[Asterisk-code-review] file conflicts: Fails second overwrite attempt if it hasn't ... (testsuite[15.6])
Jenkins2
asteriskteam at digium.com
Wed Sep 26 09:03:55 CDT 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/10275 )
Change subject: file_conflicts: Fails second overwrite attempt if it hasn't finished recording
......................................................................
file_conflicts: Fails second overwrite attempt if it hasn't finished recording
The rest_api/recording/file_conflicts test was setup in a non deterministic
fashion thus susceptible to a race condition. Instead of waiting for the actual
start/finish record events to trigger the next step the test instead waited a
short amount of time. This sometimes caused the next step to execute too early.
This patch makes it so test checks/steps are triggered via appropriate events.
Change-Id: Ifc8fc2ec94cf159a886b9ab8cf8615bbfda96315
---
M tests/rest_api/recording/file_conflicts/recording.py
M tests/rest_api/recording/file_conflicts/test-config.yaml
2 files changed, 59 insertions(+), 63 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/tests/rest_api/recording/file_conflicts/recording.py b/tests/rest_api/recording/file_conflicts/recording.py
index 8c3a954..9062661 100644
--- a/tests/rest_api/recording/file_conflicts/recording.py
+++ b/tests/rest_api/recording/file_conflicts/recording.py
@@ -16,18 +16,21 @@
class TestLogic(object):
def __init__(self):
self.channel_id = None
+ self.step = 'baseline'
+
TEST = TestLogic()
-def fail_test():
+def fail_test(msg):
+ LOGGER.error(msg)
TEST.test_object.set_passed(False)
TEST.test_object.stop_reactor()
+ return True
def on_start(ari, event, test_object):
TEST.test_object = test_object
- TEST.ari = ari
LOGGER.debug("on_start(%r)" % event)
TEST.channel_id = event['channel']['id']
@@ -36,91 +39,68 @@
LOGGER.info("Attempting to answer the channel.")
try:
- TEST.ari.post('channels', TEST.channel_id, 'answer')
+ ari.post('channels', TEST.channel_id, 'answer')
except requests.exceptions.HTTPError:
- LOGGER.error('Failed to answer.')
- fail_test()
- return True
+ return fail_test('Failed to answer.')
LOGGER.info("Answered the channel. Starting the baseline recording.")
try:
- TEST.ari.post('channels', TEST.channel_id, 'record',
+ ari.post('channels', TEST.channel_id, 'record',
name="superfly", format="wav")
except requests.exceptions.HTTPError:
- LOGGER.error("Failed to record.")
- fail_test()
- return True
+ return fail_test("Failed to record.")
- LOGGER.info("Baseline recording started successfully.")
-
- # XXX No recording started events yet, so we allow time before continuing.
- reactor.callLater(0.2, step_two)
return True
-def step_two():
- LOGGER.info("Attempting to stop the baseline recording.")
+def on_recording_started(ari, event, test_object):
+ LOGGER.info("{0} recording started successfully".format(TEST.step))
+ LOGGER.info("Attempting to stop the {0} recording.".format(TEST.step))
try:
- TEST.ari.post('recordings/live', 'superfly', 'stop')
+ ari.post('recordings/live', 'superfly', 'stop')
except requests.exceptions.HTTPError:
- LOGGER.error('Failed to stop recording.')
- fail_test()
- return
+ return fail_test('Failed to stop {0} recording.'.format(TEST.step))
- LOGGER.info("Baseline recording stopped.")
- LOGGER.info("Attempting to start expected failure recording: "
- "(file name conflict).")
+ return True
+
+
+def on_recording_finished(ari, event, test_object):
+ LOGGER.info("{0} recording stopped successfully.".format(TEST.step))
+
+ if TEST.step == 'overwrite':
+ # Once done with the overwrite recording end the test
+ LOGGER.info("Time to leave stasis.")
+
+ try:
+ ari.post('channels', TEST.channel_id, 'continue')
+ except requests.exceptions.HTTPError:
+ return fail_test('Failed to leave stasis.')
+
+ LOGGER.info("Tests completed: The channel should be out of stasis.")
+ return True
+
+ # Baseline recording done, so attempt overwrite tests
+ TEST.step = 'overwrite'
+ LOGGER.info("First overwrite attempt (expecting failure).")
try:
# Overwrite is not allowed and the file will already exist,
# so this should fail.
- TEST.ari.post('channels', TEST.channel_id, 'record',
- name="superfly", format="wav",
- ifExists="fail")
- LOGGER.error('This recording was supposed to fail and it did not.')
- fail_test()
- return
+ ari.post('channels', TEST.channel_id, 'record', name="superfly",
+ format="wav", ifExists="fail")
+ return fail_test('First overwrite attempt did not fail.')
except requests.exceptions.HTTPError:
pass
- LOGGER.info("The recording failed as expected.")
- LOGGER.info("Attempting to start recording with overwrite enabled")
+ LOGGER.info("Second overwrite attempt (expecting success).")
try:
# Overwrite is allowed, so recording should succeed this time.
- TEST.ari.post('channels', TEST.channel_id, 'record',
- name="superfly", format="wav",
- ifExists="overwrite")
+ ari.post('channels', TEST.channel_id, 'record', name="superfly",
+ format="wav", ifExists="overwrite")
except requests.exceptions.HTTPError:
- LOGGER.error('Failed to record in overwrite mode.')
- fail_test()
- return
+ return fail_test('Failed to record in overwrite mode.')
- LOGGER.info("The overwrite recording started successfully")
-
- # XXX No recording started events yet, so we allow time before continuing.
- reactor.callLater(0.2, step_three)
-
-
-def step_three():
- LOGGER.info("Attempting to stop the overwrite recording")
-
- try:
- TEST.ari.post('recordings/live', 'superfly', 'stop')
- except requests.exceptions.HTTPError:
- LOGGER.error('Failed to stop overwrite recording.')
- fail_test()
- return
-
- LOGGER.info("Overwrite recording stopped successfully. Leave Stasis.")
-
- try:
- TEST.ari.post('channels', TEST.channel_id, 'continue')
- except requests.exceptions.HTTPError:
- LOGGER.error('Failed to leave stasis. Crud.')
- fail_test()
- return
-
- LOGGER.info("All tests complete: The channel should be out of stasis.")
+ return True
diff --git a/tests/rest_api/recording/file_conflicts/test-config.yaml b/tests/rest_api/recording/file_conflicts/test-config.yaml
index 68a51c8..cecb087 100644
--- a/tests/rest_api/recording/file_conflicts/test-config.yaml
+++ b/tests/rest_api/recording/file_conflicts/test-config.yaml
@@ -25,6 +25,22 @@
callback:
module: recording
method: on_start
+ - conditions:
+ match:
+ type: RecordingStarted
+ application: testsuite
+ count: 2
+ callback:
+ module: recording
+ method: on_recording_started
+ - conditions:
+ match:
+ type: RecordingFinished
+ application: testsuite
+ count: 2
+ callback:
+ module: recording
+ method: on_recording_finished
properties:
dependencies:
--
To view, visit https://gerrit.asterisk.org/10275
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 15.6
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc8fc2ec94cf159a886b9ab8cf8615bbfda96315
Gerrit-Change-Number: 10275
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180926/99cdbd8c/attachment-0001.html>
More information about the asterisk-code-review
mailing list