[svn-commits] jpeeler: branch jpeeler/event_watcher r265 - /asterisk/team/jpeeler/event_wat...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Apr 29 13:46:51 CDT 2010


Author: jpeeler
Date: Thu Apr 29 13:46:48 2010
New Revision: 265

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=265
Log:
handle calling timeout in client module and add locking to ensure reactor is only stopped once

Modified:
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py?view=diff&rev=265&r1=264&r2=265
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py Thu Apr 29 13:46:48 2010
@@ -3,11 +3,12 @@
 from twisted.application import service, internet
 from twisted.internet import reactor
 from starpy import manager, fastagi, utilapplication, menu
-import os, logging, pprint, time, sys
+import os, logging, pprint, time, sys, threading
 
 try:
     sys.path.append("lib/python")
     from asterisk.asterisk import Asterisk
+    STANDALONE = False
 except ImportError:
     print "Running in standalone mode"
     STANDALONE = True
@@ -37,6 +38,10 @@
         self.ami = None
         self.testcount = 0
         self.passed = True
+        self.callID = None
+
+        self.reactorLock = threading.Lock()
+        self.reactor_stopped = False
 
         self.clear_vars()
 
@@ -97,7 +102,21 @@
     def timeout(self):
         print "DEBUG: timed out"
         self.passed = False
-        reactor.stop()
+        self.reactorLock.acquire()
+        if not self.reactor_stopped:
+            reactor.stop()
+            self.reactor_stopped = True
+        self.reactorLock.release()
+        self.stop_asterisk()
+
+    def end_test(self):
+        self.reactorLock.acquire()
+        if not self.reactor_stopped:
+            self.callID.cancel()
+            reactor.stop()
+            self.reactor_stopped = True
+        self.reactorLock.release()
+        self.log.critical("DEBUG: DONE, end_test")
         self.stop_asterisk()
 
     def dict_in_dict(self, d_set, d_subset):
@@ -180,12 +199,6 @@
                     if self.count == 0:
                         self.loadNextTest(ami)
                     continue
-
-    def end_test(self):
-        if reactor.running:
-            reactor.stop()
-        self.log.critical("DEBUG: DONE, end_test")
-        self.stop_asterisk()
  
     def next_test(self, count, toexec):
         print "NEXT TEST YAYA ", count
@@ -195,13 +208,14 @@
              return -1
 
         print "DEBUG: next test exists"
-        if self.testobj.callID:
-            self.testobj.callID.cancel()
-            self.testobj.callID = reactor.callLater(5, self.timeout)
+        if self.callID:
+            self.callID.cancel()
         method = getattr(self.testobj, toexec)
         method(self)
         if len(self.eventList) > 0:
-             return 0
+            print "DEBUG: Rescheduling timeout"
+            self.callID = reactor.callLater(5, self.timeout)
+            return 0
     
         print "DEBUG: returning, no events..."
         return -1 # exception or something

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test?view=diff&rev=265&r1=264&r2=265
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test Thu Apr 29 13:46:48 2010
@@ -10,24 +10,23 @@
 
 class Test():
 
-    def __init__(self):
-        callID = None
-
     def test0(self, watcher):
         print "WOOT! - test0"
+        #time.sleep(3)
         event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
         watcher.add_event(event1)
         event_send = {'Action' : 'ping'}
         watcher.add_send_event(event_send)
         print "ENDWOOT"
     
-    #def test1(self, watcher):
-    #    print "WOOT2! - test1"
-    #    event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
-    #    watcher.add_event(event1)
-    #    event_send = {'Action' : 'ping'}
-    #    watcher.add_send_event(event_send)
-    #    print "ENDWOOT2"
+    def test1(self, watcher):
+        print "WOOT2! - test1"
+        #time.sleep(10)
+        event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
+        watcher.add_event(event1)
+        event_send = {'Action' : 'ping'}
+        watcher.add_send_event(event_send)
+        print "ENDWOOT2"
 
     #def test2(self, watcher):
         #scenario 2 with optional event matching
@@ -56,7 +55,6 @@
         watcher.set_test_obj(self)
     
         reactor.callWhenRunning(watcher.start)
-        self.callID = reactor.callLater(5, watcher.timeout)
         reactor.run()
             
         if watcher.passed:




More information about the svn-commits mailing list