[asterisk-commits] mjordan: testsuite/asterisk/trunk r2915 - /asterisk/trunk/tests/queues/queue_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 16 10:41:23 CST 2011


Author: mjordan
Date: Fri Dec 16 10:41:19 2011
New Revision: 2915

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2915
Log:
Ported from lua to python to better aid in debugging if test fails

Added:
    asterisk/trunk/tests/queues/queue_baseline/run-test.lua
      - copied unchanged from r2868, asterisk/trunk/tests/queues/queue_baseline/run-test
Modified:
    asterisk/trunk/tests/queues/queue_baseline/run-test
    asterisk/trunk/tests/queues/queue_baseline/test-config.yaml

Modified: asterisk/trunk/tests/queues/queue_baseline/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/queue_baseline/run-test?view=diff&rev=2915&r1=2914&r2=2915
==============================================================================
--- asterisk/trunk/tests/queues/queue_baseline/run-test (original)
+++ asterisk/trunk/tests/queues/queue_baseline/run-test Fri Dec 16 10:41:19 2011
@@ -1,3 +1,84 @@
-#!/usr/bin/env bash
-. lib/sh/lua.sh
-asttest -a / -s `dirname $0` $@
+#!/usr/bin/env python
+# vim: sw=3 et:
+'''
+Copyright (C) 2011, Digium, Inc.
+Matt Jordan <mjordan at digium.com>
+
+Ported from original lua queue_baseline test by Matt Nicholson
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+import logging
+
+
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+
+from asterisk.TestCase import TestCase
+
+logger = logging.getLogger(__name__)
+
+
+class QueueBaseline(TestCase):
+
+    def __init__(self):
+        super(QueueBaseline, self).__init__()
+
+        self.expected_events = {
+            "Join": False,
+            "AgentCalled": False,
+            "AgentConnect": False,
+            "Leave": False,
+            "AgentComplete": False
+            }
+        self.events_received = 0
+        self.create_asterisk()
+
+    def run(self):
+        super(QueueBaseline, self).run()
+        self.create_ami_factory()
+
+    def ami_connect(self, ami):
+        """ Register for all events we care about """
+        for event in self.expected_events:
+            logger.debug("Registering for %s" % event)
+            ami.registerEvent(event, self.queue_event)
+
+        df = ami.originate(channel = "Local/test at test_context", exten = "queue", context = "test_context", priority = 1)
+        df.addErrback(self.handleOriginateFailure)
+
+    def queue_event(self, ami, event):
+        if event['event'] in self.expected_events:
+            logger.info("Received expected event %s" % event['event'])
+            self.events_received += 1
+            self.expected_events[event['event']] = True
+            if self.events_received == len(self.expected_events):
+                logger.info("Received all expected events; stopping")
+                self.passed = True
+                self.stop_reactor()
+        else:
+            logger.debug("Passing on non-expected event %s" % event['event'])
+
+
+def main():
+    test = QueueBaseline()
+    test.start_asterisk()
+    reactor.run()
+    test.stop_asterisk()
+
+    if not test.passed:
+        """ We missed an event - query the test to find out which one """
+        for event in test.expected_events:
+            if not test.expected_events[event]:
+                logger.error("Test failed: did not receive expected event %s" % event)
+        return 1
+
+    return 0
+
+if __name__ == "__main__":
+   sys.exit(main() or 0)

Modified: asterisk/trunk/tests/queues/queue_baseline/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/queues/queue_baseline/test-config.yaml?view=diff&rev=2915&r1=2914&r2=2915
==============================================================================
--- asterisk/trunk/tests/queues/queue_baseline/test-config.yaml (original)
+++ asterisk/trunk/tests/queues/queue_baseline/test-config.yaml Fri Dec 16 10:41:19 2011
@@ -8,4 +8,4 @@
 properties:
     minversion: '1.4'
     dependencies:
-        - app: 'asttest'
+        - asterisk: 'app_queue'




More information about the asterisk-commits mailing list