|
|
@ -183,7 +183,7 @@ class IterTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
select = self.klass([recv])
|
|
|
|
select = self.klass([recv])
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
recv._on_receive(msg)
|
|
|
|
recv._on_receive(msg)
|
|
|
|
self.assertEquals([(recv, (msg, '123'))], list(select))
|
|
|
|
self.assertEquals([msg], list(select))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OneShotTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
class OneShotTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
@ -194,7 +194,7 @@ class OneShotTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
select = self.klass([recv])
|
|
|
|
select = self.klass([recv])
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
recv._on_receive(msg)
|
|
|
|
recv._on_receive(msg)
|
|
|
|
recv, (msg_, data) = select.get()
|
|
|
|
msg_ = select.get()
|
|
|
|
self.assertEquals(msg, msg_)
|
|
|
|
self.assertEquals(msg, msg_)
|
|
|
|
self.assertEquals(0, len(select._receivers))
|
|
|
|
self.assertEquals(0, len(select._receivers))
|
|
|
|
self.assertEquals(None, recv.notify)
|
|
|
|
self.assertEquals(None, recv.notify)
|
|
|
@ -204,7 +204,8 @@ class OneShotTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
select = self.klass([recv], oneshot=False)
|
|
|
|
select = self.klass([recv], oneshot=False)
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
msg = mitogen.core.Message.pickled('123')
|
|
|
|
recv._on_receive(msg)
|
|
|
|
recv._on_receive(msg)
|
|
|
|
self.assertEquals((recv, (msg, '123')), select.get())
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(msg, select.get())
|
|
|
|
self.assertEquals(1, len(select._receivers))
|
|
|
|
self.assertEquals(1, len(select._receivers))
|
|
|
|
self.assertEquals(recv, select._receivers[0])
|
|
|
|
self.assertEquals(recv, select._receivers[0])
|
|
|
|
self.assertEquals(select._put, recv.notify)
|
|
|
|
self.assertEquals(select._put, recv.notify)
|
|
|
@ -241,22 +242,29 @@ class GetTest(testlib.RouterMixin, testlib.TestCase):
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
select = self.klass([recv])
|
|
|
|
select = self.klass([recv])
|
|
|
|
recv, (msg, data) = select.get()
|
|
|
|
msg = select.get()
|
|
|
|
self.assertEquals('123', data)
|
|
|
|
self.assertEquals('123', msg.unpickle())
|
|
|
|
|
|
|
|
|
|
|
|
def test_nonempty_after_add(self):
|
|
|
|
def test_nonempty_after_add(self):
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
select = self.klass([recv])
|
|
|
|
select = self.klass([recv])
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
recv, (msg, data) = select.get()
|
|
|
|
msg = select.get()
|
|
|
|
self.assertEquals('123', data)
|
|
|
|
self.assertEquals('123', msg.unpickle())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_nonempty_receiver_attr_set(self):
|
|
|
|
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
|
|
|
|
select = self.klass([recv])
|
|
|
|
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
|
|
|
|
msg = select.get()
|
|
|
|
|
|
|
|
self.assertEquals(msg.receiver, recv)
|
|
|
|
|
|
|
|
|
|
|
|
def test_drained_by_other_thread(self):
|
|
|
|
def test_drained_by_other_thread(self):
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
recv = mitogen.core.Receiver(self.router)
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
recv._on_receive(mitogen.core.Message.pickled('123'))
|
|
|
|
select = self.klass([recv])
|
|
|
|
select = self.klass([recv])
|
|
|
|
msg, data = recv.get()
|
|
|
|
msg = recv.get()
|
|
|
|
self.assertEquals('123', data)
|
|
|
|
self.assertEquals('123', msg.unpickle())
|
|
|
|
self.assertRaises(mitogen.core.TimeoutError,
|
|
|
|
self.assertRaises(mitogen.core.TimeoutError,
|
|
|
|
lambda: select.get(timeout=0.0))
|
|
|
|
lambda: select.get(timeout=0.0))
|
|
|
|
|
|
|
|
|
|
|
|