Exemplo n.º 1
0
 def test_add_callback(self):
     ioloop = pulsar.thread_ioloop()
     d = pulsar.Deferred()
     ioloop.add_callback(lambda: d.callback(current_thread().ident))
     # we should be able to wait less than a second
     yield d
     self.assertEqual(d.result, ioloop.tid)
Exemplo n.º 2
0
Arquivo: me.py Projeto: cyberj/pulsar
 def testIOloop(self):
     worker = pulsar.get_actor()
     ioloop = pulsar.thread_ioloop()
     self.assertTrue(ioloop.running())
     self.assertNotEqual(worker.requestloop, ioloop)
     self.assertEqual(worker.ioloop, ioloop)
     self.assertEqual(worker.tid, worker.requestloop.tid)
     self.assertNotEqual(worker.tid, ioloop.tid)
     self.assertTrue(str(ioloop))
     self.assertFalse(ioloop.start())
Exemplo n.º 3
0
 def test_periodic(self):
     ioloop = pulsar.thread_ioloop()
     d = pulsar.Deferred()
     class p:
         def __init__(self):
             self.c = 0
         def __call__(self, periodic):
             self.c += 1
             if self.c == 2:
                 raise ValueError()
             elif self.c == 3:
                 periodic.stop()
                 d.callback(self.c)
     periodic = ioloop.add_periodic(p(), 1)
     yield d
     self.assertEqual(d.result, 3)
     self.assertFalse(periodic._running)
     
     
     
     
Exemplo n.º 4
0
 def test_add_timeout(self):
     ioloop = pulsar.thread_ioloop()
     d = pulsar.Deferred()
     now = time.time()
     timeout1 = ioloop.add_timeout(now+20,
                         lambda: d.callback(current_thread().ident))
     timeout2 = ioloop.add_timeout(now+10,
                         lambda: d.callback(current_thread().ident))
     # lets wake the ioloop
     ioloop.wake()
     self.assertTrue(timeout1 in ioloop._timeouts)
     self.assertTrue(timeout2 in ioloop._timeouts)
     ioloop.remove_timeout(timeout1)
     ioloop.remove_timeout(timeout2)
     self.assertFalse(timeout1 in ioloop._timeouts)
     self.assertFalse(timeout2 in ioloop._timeouts)
     timeout1 = ioloop.add_timeout(now+0.1,
                         lambda: d.callback(current_thread().ident))
     ioloop.wake()
     time.sleep(0.2)
     self.assertTrue(d.called)
     self.assertEqual(d.result, ioloop.tid)
     self.assertFalse(timeout1 in ioloop._timeouts)
Exemplo n.º 5
0
 def testIOloop(self):
     ioloop = pulsar.thread_ioloop()
     self.assertTrue(ioloop)
     self.assertNotEqual(ioloop.tid, current_thread().ident)