|
|
@ -1,4 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import unittest2
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
|
|
|
|
import mitogen.core
|
|
|
|
import mitogen.core
|
|
|
@ -36,5 +38,43 @@ class IterationTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
self.assertEquals(10, ret.get().unpickle())
|
|
|
|
self.assertEquals(10, ret.get().unpickle())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CloseTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
|
|
|
|
def wait(self, latch, wait_recv):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
latch.put(wait_recv.get())
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
latch.put(sys.exc_info()[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_closes_one(self):
|
|
|
|
|
|
|
|
latch = mitogen.core.Latch()
|
|
|
|
|
|
|
|
wait_recv = mitogen.core.Receiver(self.router)
|
|
|
|
|
|
|
|
t = threading.Thread(target=lambda: self.wait(latch, wait_recv))
|
|
|
|
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
wait_recv.close()
|
|
|
|
|
|
|
|
def throw():
|
|
|
|
|
|
|
|
raise latch.get()
|
|
|
|
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
e = self.assertRaises(mitogen.core.ChannelError, throw)
|
|
|
|
|
|
|
|
self.assertEquals(e.args[0], mitogen.core.Receiver.closed_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_closes_all(self):
|
|
|
|
|
|
|
|
latch = mitogen.core.Latch()
|
|
|
|
|
|
|
|
wait_recv = mitogen.core.Receiver(self.router)
|
|
|
|
|
|
|
|
ts = [
|
|
|
|
|
|
|
|
threading.Thread(target=lambda: self.wait(latch, wait_recv))
|
|
|
|
|
|
|
|
for x in range(5)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
for t in ts:
|
|
|
|
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
wait_recv.close()
|
|
|
|
|
|
|
|
def throw():
|
|
|
|
|
|
|
|
raise latch.get()
|
|
|
|
|
|
|
|
for x in range(5):
|
|
|
|
|
|
|
|
e = self.assertRaises(mitogen.core.ChannelError, throw)
|
|
|
|
|
|
|
|
self.assertEquals(e.args[0], mitogen.core.Receiver.closed_msg)
|
|
|
|
|
|
|
|
for t in ts:
|
|
|
|
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|
|
|
|
unittest2.main()
|
|
|
|