[asterisk-commits] coreyfarrell: testsuite/asterisk/trunk r5832 - /asterisk/trunk/tests/pbx/dial...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 31 20:02:54 CDT 2014


Author: coreyfarrell
Date: Fri Oct 31 20:02:48 2014
New Revision: 5832

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5832
Log:
Fix freeze on tests/pbx/dialplan_reload

* Make use of 'core waitfullybooted' to ensure restarts complete
* Remove unused variables
* Use global variable to specify number of iterations
* Decrease reactor_timeout from 300 to 30, use reset_timeout per iteration
* Fix PEP8 issues

Review: https://reviewboard.asterisk.org/r/4122/

Modified:
    asterisk/trunk/tests/pbx/dialplan_reload/run-test

Modified: asterisk/trunk/tests/pbx/dialplan_reload/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/dialplan_reload/run-test?view=diff&rev=5832&r1=5831&r2=5832
==============================================================================
--- asterisk/trunk/tests/pbx/dialplan_reload/run-test (original)
+++ asterisk/trunk/tests/pbx/dialplan_reload/run-test Fri Oct 31 20:02:48 2014
@@ -15,33 +15,34 @@
 from asterisk.test_case import TestCase
 LOGGER = logging.getLogger(__name__)
 
-workingdir = "dialplan-reload"
-testdir = "tests/%s" % workingdir
+# How many times to do the restart cycle
+restart_iterations = 5
+
 
 class DialplanReloadTest(TestCase):
     count = 0
 
     def __init__(self):
         TestCase.__init__(self)
-        # artificially high timeout as this can take a while
-        self.reactor_timeout = 300
+        # Each iteration resets the timeout
+        self.reactor_timeout = 30
         self.create_asterisk(1)
 
     def run(self):
         TestCase.run(self)
 
         def callback(defer):
-            LOGGER.info("DIALPLAN SHOW = " + defer.output);
+            LOGGER.info("DIALPLAN SHOW = %s" % defer.output)
             print defer.output.strip()
             if defer.output.find("CID match ''") == -1:
                 print "Dialplan did not load correctly"
-                reactor.callLater(1,self.failure)
+                self.failure()
             else:
-                reactor.callLater(3,self.reload)
+                self.reload()
 
         def errback(failure):
-            LOGGER.error("CLI dialplan show failed");
-            reactor.callLater(1,self.failure)
+            LOGGER.error("CLI dialplan show failed")
+            self.failure()
 
         # log the trouble context just to be sure it was loaded
         df = self.ast[0].cli_exec("dialplan show incoming_1")
@@ -51,23 +52,36 @@
     def reload(self):
 
         def callback(defer):
-            LOGGER.info("RESTART = " + defer.output)
-            print "Restart #" + str(self.count) + " = " + defer.output.strip()
+            def fullybooted_success(defer):
+                LOGGER.info("core waitfullybooted success")
+                if self.count == restart_iterations:
+                    self.success()
+                else:
+                    self.reload()
+
+            def fullybooted_failure(failure):
+                LOGGER.error("core waitfullybooted failed")
+                self.failure()
+
+            def fullybooted_run():
+                self.reset_timeout()
+                waitfullybooted = self.ast[0].cli_exec("core waitfullybooted")
+                waitfullybooted.addCallback(fullybooted_success)
+                waitfullybooted.addErrback(fullybooted_failure)
+
+            LOGGER.info("Restarted #%d" % self.count)
             self.count += 1
-            if self.count == 50:
-                reactor.callLater(3,self.success)
-            else:
-                reactor.callLater(3,self.reload)
+            reactor.callLater(3, fullybooted_run)
 
         def errback(failure):
             LOGGER.error("CLI restart failed")
-            reactor.callLater(1,self.failure)
+            self.failure()
 
         df = self.ast[0].cli_exec("core restart gracefully")
         df.addCallback(callback)
         df.addErrback(errback)
 
-        LOGGER.info("Restarted # " + str(self.count))
+        LOGGER.info("Restarting #%d" % self.count)
 
     def success(self):
         self.passed = True
@@ -75,6 +89,7 @@
 
     def failure(self):
         self.stop_reactor()
+
 
 def main():
     test = DialplanReloadTest()




More information about the asterisk-commits mailing list