[asterisk-commits] jrose: testsuite/asterisk/trunk r3497 - in /asterisk/trunk/tests/apps/mixmoni...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 30 14:22:17 CDT 2012


Author: jrose
Date: Tue Oct 30 14:22:14 2012
New Revision: 3497

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3497
Log:
testsuite: Get mixmonitor_audiohook_inherit working again

This patch changes mixmonitor_audiohook_inherit to use more ami event driven
logic as well as just generally gets it to start running again.

Added:
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf   (with props)
Removed:
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/manager.conf
Modified:
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/extensions.conf
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/test-config.yaml

Modified: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/extensions.conf?view=diff&rev=3497&r1=3496&r2=3497
==============================================================================
--- asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/extensions.conf Tue Oct 30 14:22:14 2012
@@ -8,17 +8,20 @@
 
 [ast1]
 exten => 101,1,Answer()
-exten => 101,n,MixMonitor(${TESTAUDIO1})
+exten => 101,n,MixMonitor(testaudio1.raw)
 exten => 101,n,Set(AUDIOHOOK_INHERIT(MixMonitor)=yes)
 exten => 101,n,Dial(Local/2000 at mixmonitortest,,tT)
 
 [mixmonitortest]
 exten => 2000,1,Answer()
-exten => 2000,n,SendDTMF(#)
+exten => 2000,n,Playback(demo-thanks)
+exten => 2000,n,SendDTMF(*2)
 exten => 2000,n,SendDTMF(1w2w3w4w)
+exten => 2000,n,Playback(demo-thanks)
+exten => 2000,n,HangUp()
 
 exten => 1234,1,Answer()
-exten => 1234,n,Playback(demo-thanks)
-exten => 1234,n,StopMixMonitor()
-exten => 1234,n,UserEvent(test1, status: SUCCESS)
-exten => 1234,n,Hangup()
+exten => 1234,n,Playback(demo-thanks) ; pad length while waiting for exten 2000 to hangup.
+exten => 1234,n,Playback(demo-thanks) ; pad a little more length to give 101 time to be transferred so that the masqueraded channel can go away.
+exten => 1234,n,UserEvent(stop_mix_test, status: CHECKSTOP) ; If mixmonitor has already stopped, that means inherit didn't work properly.
+exten => 1234,n,Playback(demo-thanks) ; This should be recorded by the mixmonitor in 101

Added: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf?view=auto&rev=3497
==============================================================================
--- asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf (added)
+++ asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf Tue Oct 30 14:22:14 2012
@@ -1,0 +1,3 @@
+[general]
+[featuremap]
+atxfer => *2                   ; Attended transfer  -- Make sure to set the T and/or t option in the Dial() or Queue()  app call!

Propchange: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Rev URL"

Propchange: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/configs/ast1/features.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test?view=diff&rev=3497&r1=3496&r2=3497
==============================================================================
--- asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test (original)
+++ asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test Tue Oct 30 14:22:14 2012
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 '''
-Copyright (C) 2010, Digium, Inc.
+Copyright (C) 2010-2012, Digium, Inc.
 David Vossel <dvossel at digium.com>
 
 This program is free software, distributed under the terms of
@@ -9,108 +9,121 @@
 
 import sys
 import os
-import math
-from twisted.internet import reactor
-from starpy import manager
+import logging
 
 sys.path.append("lib/python")
-from asterisk.asterisk import Asterisk
+from twisted.internet import reactor
+from asterisk.TestCase import TestCase
 
-workingdir = "mixmonitor_audiohook_inherit"
-testdir = "tests/%s" % workingdir
+LOGGER = logging.getLogger(__name__)
 
-class MixMonitorTest:
+class MixMonitorAHookInheritTest(TestCase):
+    """
+    This test case starts a mixmonitored call which will then be transferred
+    using AUDIOHOOK_INHERIT to another recipient. It checks to make sure
+    MixMonitor isn't ended by the transfer.
+    """
     def __init__(self):
-        self.passed = False
-        self.last_step = ""
-        # if audiohook inherit does not work, file will be much smaller than 150000 bytes
-        self.expectedfilesize = 120000
-        self.audiofile1size = -1
+        TestCase.__init__(self)
 
-        reactor.callWhenRunning(self.run)
+        # This is a minimum. Anything above this size will be acceptable.
+        self.expected_filesize = 300000
+        self.check_stop_passed = False
+        self.create_asterisk()
 
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
-        self.audiofile1 = os.path.join(os.getcwd(), "%s/testaudio1" % (testdir))
+    def run(self):
+        """
+        run and get AMI going
+        """
+        TestCase.run(self)
+        self.create_ami_factory()
 
-    def stop_reactor(self):
-        print "Stopping Reactor ..."
-        if reactor.running:
-            reactor.stop()
+    def ami_connect(self, ami):
+        """
+        On successful AMI connection, we register events and get things started
+        """
+        ami.registerEvent("UserEvent", self.cb_check_test)
+        ami.registerEvent("TestEvent", self.cb_check_mixmonitor_stop)
+        self.__launch_test(ami)
 
-    def read_result(self):
-        self.passed = True
-        self.stop_reactor()
+    def cb_check_mixmonitor_stop(self, ami, event):
+        """
+        When we receive a test event, we make sure it is a MIXMONITOR_END event
+        On ending the MixMonitor, if a flag indicating that mixmonitor stop is
+        allowed hasn't been raised yet, we fail immediately. Otherwise the test
+        will be determined by __read_result().
+        """
+        if event.get("state") != "MIXMONITOR_END":
+            return
 
-        self.log_last_step("Reading result file from MixMonitor")
-        if os.path.exists(self.audiofile1 + ".raw"):
-            self.audiofile1size = os.path.getsize(self.audiofile1 + ".raw")
+        if (self.check_stop_passed):
+            LOGGER.info("Stop event received properly before the "
+                        "MIXMONITOR_END event was received.")
+            self.__read_result()
+        else:
+            LOGGER.error("The MixMonitor stopped before we "
+                         "reached the checkstop point.")
+            self.stop_reactor()
 
-        self.log_last_step("audiofile1 size is %d, a negative size indicates the file was not present." % (self.audiofile1size, ))
-        if self.audiofile1size < self.expectedfilesize:
-            # if this failed mixmonitor is not creating the correct file size for the time we expect.
-            self.log_last_step("audiofile1 size is not within the size tolerance.")
-            self.passed = False
-
-        if self.passed == True:
-            self.log_last_step("Test Passed... All audio files are the correct.")
-
-    def launch_test1(self):
-        self.log_last_step("Placing call to test1 exten")
-        self.ast1.cli_originate("Local/s at listener extension 101 at ast1")
-
-    def check_test1(self, ami, event):
-        self.log_last_step("Checking Userevent")
-        if event.get("userevent").lower() != "test1":
+    def cb_check_test(self, ami, event):
+        """
+        On receiving a UserEvent of status 'CHECKSTOP', raise the flag to
+        indicate that MixMonitor is allowed to be stopped.
+        """
+        if event.get("userevent").lower() != "stop_mix_test":
             return
         status = event.get("status")
-        print ("Status of test1 is %s" % (status))
-        if status != "SUCCESS":
+
+        # CHECKSTOP must be raised before receiving MIXMONITOR_END.
+        if status == "CHECKSTOP":
+            LOGGER.info("Received the CHECKSTOP event. MixMonitor stopping is "
+                        "now anticipated.")
+            self.check_stop_passed = True
+
+    def __launch_test(self, ami):
+        """
+        Originate the call
+        """
+        LOGGER.info("Starting call")
+        ami.originate("Local/s at listener",exten = "101",\
+            context = "ast1",priority = 1).addErrback(self.handleOriginateFailure)
+
+    def __read_result(self):
+        """
+        Validate that the MixMonitor actually recorded a file of some length to
+        determine final success/failure.
+        """
+        audiofile = "%s%s/%s" % (self.ast[0].base,
+            self.ast[0].directories['astspooldir'], "monitor/testaudio1.raw")
+
+        if not os.path.exists(audiofile):
+            LOGGER.error("Path to %s did not exist. Test Failed." % audiofile)
             self.stop_reactor()
             return
 
-        self.read_result()
+        size = os.path.getsize(audiofile)
 
-    def ami_on_connect1(self, ami):
-        self.log_last_step("Connected to AMI 1")
-        self.ami = ami
-        self.ami.registerEvent("UserEvent", self.check_test1)
-        self.ami.setVar(channel = "", variable = "TESTAUDIO1", value = self.audiofile1)
+        if size >= self.expected_filesize:
+            LOGGER.info("Recording of size %d meets the acceptable minimum of "
+                        "%d. Test Passed." % (size, self.expected_filesize))
+            self.passed = True
+        else:
+            LOGGER.error("Recording of Size %d is below acceptable minimum "
+                         "%d. Test Failed." % (size, self.expected_filesize))
 
-    def ami_login_error(self, ami):
-        self.log_last_step("AMI login failed")
         self.stop_reactor()
 
-    def ami_login(self):
-        self.log_last_step("Logging in to the AMI")
-        self.ami_factory1 = manager.AMIFactory("user", "mysecret")
-        self.ami_factory1.login('127.0.0.1', 5038).addCallbacks(self.ami_on_connect1, self.ami_login_error)
+def main():
+    """
+    Start the Show
+    """
+    test = MixMonitorAHookInheritTest()
+    reactor.run()
 
-    def start_asterisk(self):
-        self.log_last_step("Starting Asterisk")
-        self.ast1.start()
-
-    def stop_asterisk(self):
-        self.ast1.stop()
-
-    def log_last_step(self, step):
-        print step
-        self.last_step = step
-
-    def run(self):
-        self.ami_login()
-        self.launch_test1()
-
-        reactor.callLater(60, self.stop_reactor)
-
-def main():
-    test = MixMonitorTest()
-    test.start_asterisk()
-    reactor.run()
-    test.stop_asterisk()
     if test.passed:
         return 0
-    return 1
+    else:
+        return 1
 
 if __name__ == "__main__":
     sys.exit(main() or 0)

Modified: asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/test-config.yaml?view=diff&rev=3497&r1=3496&r2=3497
==============================================================================
--- asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/test-config.yaml Tue Oct 30 14:22:14 2012
@@ -1,20 +1,26 @@
 testinfo:
-    skip: 'Skip while failures are debugged'
+#    skip: 'Skip while failures are debugged'
     summary:     'Test MixMonitor with AUDIOHOOK_INHERIT'
     description: |
-        'This test verifies basic functionality using MixMonitor with AUDIOHOOK_INHERIT.
-         To test this, an extension is called using the console channel driver. MixMonitor
-         and AUDIOHOOK_INHERIT are used on that channel and then the channel is transfered
-         to another extension.  After the transfer, audio is played back for a period of time. 
-         In order to verify AUDIOHOOK_INHERIT worked properly, the file size is checked to verify
-         it is the size we would expect.  If AUDIOHOOK_INHERIT did not work properly, the file 
-         size would be much smaller than what we expect since we play several seconds of audio after 
-         the transfer.'
+        'This test verifies basic functionality using MixMonitor with
+         AUDIOHOOK_INHERIT. To test this, an extension is called using the
+         Local channel driver. MixMonitor and AUDIOHOOK_INHERIT are used on
+         that channel and then the channel is transfered to another extension.
+         After the transfer, audio is played back for a period of time. In
+         order to verify AUDIOHOOK_INHERIT worked properly, the AMI listener
+         will check for a user event and a test event indicating that a
+         MixMonitor is ending. If the MixMonitor Ending event comes before the
+         user event, the test is failed since that indicates the audiohook
+         was not bound to the channel that sent the user event. If that
+         succeeds, the recording file size is checked to verify it is the size
+         we would expect.  If AUDIOHOOK_INHERIT did not work properly, the file
+         size would be much smaller than what we expect since we play several
+         seconds of audio after the transfer.'
 
 properties:
-    minversion: '1.8.0.0'
+    minversion: '1.8.19.0'
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
     tags:
-        - mixmonitor
+        - mixmonitor




More information about the asterisk-commits mailing list