<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10275">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">file_conflicts: Fails second overwrite attempt if it hasn't finished recording<br><br>The rest_api/recording/file_conflicts test was setup in a non deterministic<br>fashion thus susceptible to a race condition. Instead of waiting for the actual<br>start/finish record events to trigger the next step the test instead waited a<br>short amount of time. This sometimes caused the next step to execute too early.<br><br>This patch makes it so test checks/steps are triggered via appropriate events.<br><br>Change-Id: Ifc8fc2ec94cf159a886b9ab8cf8615bbfda96315<br>---<br>M tests/rest_api/recording/file_conflicts/recording.py<br>M tests/rest_api/recording/file_conflicts/test-config.yaml<br>2 files changed, 59 insertions(+), 63 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/rest_api/recording/file_conflicts/recording.py b/tests/rest_api/recording/file_conflicts/recording.py</span><br><span>index 8c3a954..9062661 100644</span><br><span>--- a/tests/rest_api/recording/file_conflicts/recording.py</span><br><span>+++ b/tests/rest_api/recording/file_conflicts/recording.py</span><br><span>@@ -16,18 +16,21 @@</span><br><span> class TestLogic(object):</span><br><span>     def __init__(self):</span><br><span>         self.channel_id = None</span><br><span style="color: hsl(120, 100%, 40%);">+        self.step = 'baseline'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span> TEST = TestLogic()</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-def fail_test():</span><br><span style="color: hsl(120, 100%, 40%);">+def fail_test(msg):</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.error(msg)</span><br><span>     TEST.test_object.set_passed(False)</span><br><span>     TEST.test_object.stop_reactor()</span><br><span style="color: hsl(120, 100%, 40%);">+    return True</span><br><span> </span><br><span> </span><br><span> def on_start(ari, event, test_object):</span><br><span>     TEST.test_object = test_object</span><br><span style="color: hsl(0, 100%, 40%);">-    TEST.ari = ari</span><br><span> </span><br><span>     LOGGER.debug("on_start(%r)" % event)</span><br><span>     TEST.channel_id = event['channel']['id']</span><br><span>@@ -36,91 +39,68 @@</span><br><span>     LOGGER.info("Attempting to answer the channel.")</span><br><span> </span><br><span>     try:</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('channels', TEST.channel_id, 'answer')</span><br><span style="color: hsl(120, 100%, 40%);">+        ari.post('channels', TEST.channel_id, 'answer')</span><br><span>     except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('Failed to answer.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return True</span><br><span style="color: hsl(120, 100%, 40%);">+        return fail_test('Failed to answer.')</span><br><span> </span><br><span>     LOGGER.info("Answered the channel. Starting the baseline recording.")</span><br><span> </span><br><span>     try:</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('channels', TEST.channel_id, 'record',</span><br><span style="color: hsl(120, 100%, 40%);">+        ari.post('channels', TEST.channel_id, 'record',</span><br><span>                       name="superfly", format="wav")</span><br><span>     except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error("Failed to record.")</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return True</span><br><span style="color: hsl(120, 100%, 40%);">+        return fail_test("Failed to record.")</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Baseline recording started successfully.")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    # XXX No recording started events yet, so we allow time before continuing.</span><br><span style="color: hsl(0, 100%, 40%);">-    reactor.callLater(0.2, step_two)</span><br><span>     return True</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-def step_two():</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Attempting to stop the baseline recording.")</span><br><span style="color: hsl(120, 100%, 40%);">+def on_recording_started(ari, event, test_object):</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.info("{0} recording started successfully".format(TEST.step))</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.info("Attempting to stop the {0} recording.".format(TEST.step))</span><br><span> </span><br><span>     try:</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('recordings/live', 'superfly', 'stop')</span><br><span style="color: hsl(120, 100%, 40%);">+        ari.post('recordings/live', 'superfly', 'stop')</span><br><span>     except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('Failed to stop recording.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return</span><br><span style="color: hsl(120, 100%, 40%);">+        return fail_test('Failed to stop {0} recording.'.format(TEST.step))</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Baseline recording stopped.")</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Attempting to start expected failure recording: "</span><br><span style="color: hsl(0, 100%, 40%);">-                "(file name conflict).")</span><br><span style="color: hsl(120, 100%, 40%);">+    return True</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def on_recording_finished(ari, event, test_object):</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.info("{0} recording stopped successfully.".format(TEST.step))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if TEST.step == 'overwrite':</span><br><span style="color: hsl(120, 100%, 40%);">+        # Once done with the overwrite recording end the test</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGGER.info("Time to leave stasis.")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        try:</span><br><span style="color: hsl(120, 100%, 40%);">+            ari.post('channels', TEST.channel_id, 'continue')</span><br><span style="color: hsl(120, 100%, 40%);">+        except requests.exceptions.HTTPError:</span><br><span style="color: hsl(120, 100%, 40%);">+            return fail_test('Failed to leave stasis.')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGGER.info("Tests completed: The channel should be out of stasis.")</span><br><span style="color: hsl(120, 100%, 40%);">+        return True</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Baseline recording done, so attempt overwrite tests</span><br><span style="color: hsl(120, 100%, 40%);">+    TEST.step = 'overwrite'</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.info("First overwrite attempt (expecting failure).")</span><br><span> </span><br><span>     try:</span><br><span>         # Overwrite is not allowed and the file will already exist,</span><br><span>         # so this should fail.</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('channels', TEST.channel_id, 'record',</span><br><span style="color: hsl(0, 100%, 40%);">-                      name="superfly", format="wav",</span><br><span style="color: hsl(0, 100%, 40%);">-                      ifExists="fail")</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('This recording was supposed to fail and it did not.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return</span><br><span style="color: hsl(120, 100%, 40%);">+        ari.post('channels', TEST.channel_id, 'record', name="superfly",</span><br><span style="color: hsl(120, 100%, 40%);">+                      format="wav", ifExists="fail")</span><br><span style="color: hsl(120, 100%, 40%);">+        return fail_test('First overwrite attempt did not fail.')</span><br><span>     except requests.exceptions.HTTPError:</span><br><span>         pass</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("The recording failed as expected.")</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Attempting to start recording with overwrite enabled")</span><br><span style="color: hsl(120, 100%, 40%);">+    LOGGER.info("Second overwrite attempt (expecting success).")</span><br><span> </span><br><span>     try:</span><br><span>         # Overwrite is allowed, so recording should succeed this time.</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('channels', TEST.channel_id, 'record',</span><br><span style="color: hsl(0, 100%, 40%);">-                      name="superfly", format="wav",</span><br><span style="color: hsl(0, 100%, 40%);">-                      ifExists="overwrite")</span><br><span style="color: hsl(120, 100%, 40%);">+        ari.post('channels', TEST.channel_id, 'record', name="superfly",</span><br><span style="color: hsl(120, 100%, 40%);">+                      format="wav", ifExists="overwrite")</span><br><span>     except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('Failed to record in overwrite mode.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return</span><br><span style="color: hsl(120, 100%, 40%);">+        return fail_test('Failed to record in overwrite mode.')</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("The overwrite recording started successfully")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    # XXX No recording started events yet, so we allow time before continuing.</span><br><span style="color: hsl(0, 100%, 40%);">-    reactor.callLater(0.2, step_three)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-def step_three():</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Attempting to stop the overwrite recording")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    try:</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('recordings/live', 'superfly', 'stop')</span><br><span style="color: hsl(0, 100%, 40%);">-    except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('Failed to stop overwrite recording.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("Overwrite recording stopped successfully. Leave Stasis.")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    try:</span><br><span style="color: hsl(0, 100%, 40%);">-        TEST.ari.post('channels', TEST.channel_id, 'continue')</span><br><span style="color: hsl(0, 100%, 40%);">-    except requests.exceptions.HTTPError:</span><br><span style="color: hsl(0, 100%, 40%);">-        LOGGER.error('Failed to leave stasis. Crud.')</span><br><span style="color: hsl(0, 100%, 40%);">-        fail_test()</span><br><span style="color: hsl(0, 100%, 40%);">-        return</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    LOGGER.info("All tests complete: The channel should be out of stasis.")</span><br><span style="color: hsl(120, 100%, 40%);">+    return True</span><br><span>diff --git a/tests/rest_api/recording/file_conflicts/test-config.yaml b/tests/rest_api/recording/file_conflicts/test-config.yaml</span><br><span>index 68a51c8..cecb087 100644</span><br><span>--- a/tests/rest_api/recording/file_conflicts/test-config.yaml</span><br><span>+++ b/tests/rest_api/recording/file_conflicts/test-config.yaml</span><br><span>@@ -25,6 +25,22 @@</span><br><span>             callback:</span><br><span>                 module: recording</span><br><span>                 method: on_start</span><br><span style="color: hsl(120, 100%, 40%);">+        -   conditions:</span><br><span style="color: hsl(120, 100%, 40%);">+                match:</span><br><span style="color: hsl(120, 100%, 40%);">+                    type: RecordingStarted</span><br><span style="color: hsl(120, 100%, 40%);">+                    application: testsuite</span><br><span style="color: hsl(120, 100%, 40%);">+            count: 2</span><br><span style="color: hsl(120, 100%, 40%);">+            callback:</span><br><span style="color: hsl(120, 100%, 40%);">+                module: recording</span><br><span style="color: hsl(120, 100%, 40%);">+                method: on_recording_started</span><br><span style="color: hsl(120, 100%, 40%);">+        -   conditions:</span><br><span style="color: hsl(120, 100%, 40%);">+                match:</span><br><span style="color: hsl(120, 100%, 40%);">+                    type: RecordingFinished</span><br><span style="color: hsl(120, 100%, 40%);">+                    application: testsuite</span><br><span style="color: hsl(120, 100%, 40%);">+            count: 2</span><br><span style="color: hsl(120, 100%, 40%);">+            callback:</span><br><span style="color: hsl(120, 100%, 40%);">+                module: recording</span><br><span style="color: hsl(120, 100%, 40%);">+                method: on_recording_finished</span><br><span> </span><br><span> properties:</span><br><span>     dependencies:</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10275">change 10275</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10275"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 15.6 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ifc8fc2ec94cf159a886b9ab8cf8615bbfda96315 </div>
<div style="display:none"> Gerrit-Change-Number: 10275 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>