@@ -22,7 +22,6 @@ class TestCoroutine(unittest.TestCase):
2222 coroutineCalls = []
2323 @staticmethod
2424 def dummyCoroutineFunc (start = 1 , end = 5 ):
25- logging .debug ( "in dummyCoroutineFunc %d %d" % (start , end ) )
2625 for i in range (start , end ):
2726 TestCoroutine .coroutineCalls .append (i )
2827 Coroutine .wait ();
@@ -100,7 +99,7 @@ def dummyCoroutineFuncWaiting1Sec():
10099
101100 def testCoroutineCanHaveParameters (self ):
102101 def func (* args , ** kwargs ):
103- self .assertEquals (args , (1 ))
102+ self .assertEquals (args , (1 , ))
104103 self .assertEquals (kwargs , {"extra" : 2 })
105104 coroutine = Coroutine (func , 1 , extra = 2 )
106105 coroutine .call ()
@@ -118,13 +117,27 @@ def cofunc():
118117 #And running it has caused the result parameter to be checked correctly before the coroutine terminated
119118 self .assertFalse (coroutine .is_alive ())
120119
121- def testRunCoroutinesUntilFirstCompletesOrAllComplete (self ):
120+ def testRunCoroutinesUntilFirstCompletes (self ):
122121 coroutine = Coroutine .runTillFirstCompletes (Coroutine (TestCoroutine .dummyCoroutineFunc ,1 ,3 ),
123122 Coroutine (TestCoroutine .dummyCoroutineFunc ,1 ,6 ))
124123 for i in range (1 ,10 ):
125124 coroutine .call ()
126125 self .assertEquals (TestCoroutine .coroutineCalls , [1 ,1 ,2 ,2 ])
127126
127+ def testRunCoroutinesUntilAllComplete (self ):
128+ coroutine = Coroutine .runTillAllComplete (Coroutine (TestCoroutine .dummyCoroutineFunc ,1 ,3 ),
129+ Coroutine (TestCoroutine .dummyCoroutineFunc ,1 ,6 ))
130+ for i in range (1 ,10 ):
131+ coroutine .call ()
132+ self .assertEquals (TestCoroutine .coroutineCalls , [1 ,1 ,2 ,2 ,3 ,4 ,5 ])
133+
134+ def testWithTimeout (self ):
135+ Coroutine .currentTimeMillis = Mock (side_effect = [1 ,10 ,500 ,1200 ])
136+ coroutine = Coroutine (TestCoroutine .dummyCoroutineFunc ,1 ,20 ).withTimeout (1000 )
137+ for i in range (1 ,20 ):
138+ coroutine .call ()
139+ self .assertEquals (TestCoroutine .coroutineCalls , [1 ,2 ,3 ])
140+
128141
129142
130143
0 commit comments