[Asterisk-code-review] subscribe-ws: End test when all major events have been received (testsuite[master])

Matt Jordan asteriskteam at digium.com
Tue Nov 24 20:41:42 CST 2015


Matt Jordan has uploaded a new change for review.

  https://gerrit.asterisk.org/1716

Change subject: subscribe-ws: End test when all major events have been received
......................................................................

subscribe-ws: End test when all major events have been received

This test was super unreliable, due to trying to stop the test based on
interleaved events whose ordering is unreliable. Since the generic pluggable
module that manages actions and events:
(a) Has no mechanism to stop a test based on waiting for *all* received
    events, as opposed to *any* received event
(b) Cannot be easily modified to look for all events, due to exposing the
    pluggable module that manages a series of events as opposed to the
    actual events themselves to the actions
This patch opts for using its own pluggable module for the test that looks
for the expected events and, when all are received, stops the test.

Change-Id: If133d8e1c1ea6d686140aca710647c5178da7650
---
A tests/rest_api/events/subscribe-ws/subscribe-ws.py
M tests/rest_api/events/subscribe-ws/test-config.yaml
2 files changed, 61 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/16/1716/1

diff --git a/tests/rest_api/events/subscribe-ws/subscribe-ws.py b/tests/rest_api/events/subscribe-ws/subscribe-ws.py
new file mode 100644
index 0000000..cab6e47
--- /dev/null
+++ b/tests/rest_api/events/subscribe-ws/subscribe-ws.py
@@ -0,0 +1,58 @@
+"""
+Copyright (C) 2015, Digium, Inc.
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import logging
+
+LOGGER = logging.getLogger(__name__)
+
+
+class SubscribeTest(object):
+
+    def __init__(self, module_config, test_object):
+        """Constructor
+
+        Keyword Arguments:
+        test_object   The one and only test object
+        module_config Our module config
+        """
+        self.test_object = test_object
+        self.test_object.register_ami_observer(self.on_ami_connect)
+        self.test_object.register_ws_event_handler(self.on_ws_event)
+        self.events = {'BridgeDestroyed': 0,
+                       'ChannelDestroyed': 0,
+                       'DeviceStateChanged': 0}
+
+    def on_ami_connect(self, ami):
+        """AMI connect callback
+
+        AMI connects after ARI, which should indicate that our test
+        is ready to go.
+
+        Keyword Arguments:
+        ami The AMI instance
+        """
+        self.test_object.ari.post('channels',
+            endpoint='Local/dial_alice at default', extension='echo')
+
+    def on_ws_event(self, event):
+        """ARI event callback
+
+        Keyword Arguments:
+        event The received ARI event
+        """
+        event_type = event.get('type')
+        if event_type not in self.events:
+            return
+        self.events[event_type] += 1
+
+        if (self.events['BridgeDestroyed'] == 1
+            and self.events['ChannelDestroyed'] == 4
+            and self.events['DeviceStateChanged'] == 8):
+
+            LOGGER.info('All expected events received; stopping test')
+            self.test_object.stop_reactor()
diff --git a/tests/rest_api/events/subscribe-ws/test-config.yaml b/tests/rest_api/events/subscribe-ws/test-config.yaml
index a02a940..5d49538 100644
--- a/tests/rest_api/events/subscribe-ws/test-config.yaml
+++ b/tests/rest_api/events/subscribe-ws/test-config.yaml
@@ -15,22 +15,12 @@
             config-section: pluggable-config
             typename: pluggable_modules.EventActionModule
         -
-            typename: pluggable_modules.ARIHangupMonitor
+            typename: subscribe-ws.SubscribeTest
 
 test-object-config:
     subscribe-all: True
 
 pluggable-config:
-    -
-        ari-start:
-        ari-requests:
-            -
-                method: 'post'
-                uri: 'channels'
-                params:
-                    endpoint: 'Local/dial_alice at default'
-                    extension: 'echo'
-                expect: 200
     -
         # Matching of endpoint and device state subscriptions
         ari-events:
@@ -48,9 +38,7 @@
                         name: 'Local/dial_alice at default'
                         state: 'NOT_INUSE'
                 count: '>1'
-    -
-        # Matching of channel subscription
-        ari-events:
+            # Matching of channel subscription
             -
                 match:
                     type: 'ChannelCreated'
@@ -139,9 +127,7 @@
                     channel:
                         name: 'Local/dial_alice at default-00000000;2'
                 count: 1
-    -
-        # Matching of bridge subscription
-        ari-events:
+            # Matching of bridge subscription
             -
                 match:
                     type: 'BridgeCreated'

-- 
To view, visit https://gerrit.asterisk.org/1716
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If133d8e1c1ea6d686140aca710647c5178da7650
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list