示例#1
0
文件: deferred.py 项目: cyberj/pulsar
 def testNested(self):
     d = MultiDeferred()
     # add a generator
     d.append((a for a in range(1,11)))
     r = maybe_async(d.lock())
     self.assertTrue(d.locked)
     self.assertFalse(is_async(r))
     self.assertEqual(r, [[1,2,3,4,5,6,7,8,9,10]])
示例#2
0
文件: deferred.py 项目: cyberj/pulsar
 def testUpdate(self):
     d1 = Deferred()
     d2 = Deferred()
     d = MultiDeferred()
     d.update((d1,d2)).lock()
     d1.callback('first')
     d2.callback('second')
     self.assertTrue(d.called)
     self.assertEqual(d.result,['first','second'])
示例#3
0
文件: deferred.py 项目: cyberj/pulsar
 def testSimple(self):
     d = MultiDeferred()
     self.assertFalse(d.called)
     self.assertFalse(d._locked)
     self.assertFalse(d._deferred)
     self.assertFalse(d._stream)
     d.lock()
     self.assertTrue(d.called)
     self.assertTrue(d._locked)
     self.assertEqual(d.result,[])
     self.assertRaises(RuntimeError, d.lock)
     self.assertRaises(AlreadyCalledError, d._finish)
示例#4
0
文件: deferred.py 项目: cyberj/pulsar
 def testNestedhandle(self):
     handle = lambda value : reduce(lambda x,y: x+y, value)\
                  if isinstance(value, list) else value 
     d = MultiDeferred(handle_value=handle)
     d.append((a for a in range(1,11)))
     r = maybe_async(d.lock())
     self.assertFalse(is_async(r))
     self.assertEqual(r, [55])
     handle = lambda value: 'c'*value
     d = MultiDeferred(handle_value=handle)
     d.append((a for a in range(1,11)))
     r = maybe_async(d.lock())
     self.assertFalse(is_async(r))
     self.assertTrue(is_failure(r[0]))
示例#5
0
文件: deferred.py 项目: cyberj/pulsar
 def testMulti(self):
     d = MultiDeferred()
     d1 = Deferred()
     d2 = Deferred()
     d.append(d1)
     d.append(d2)
     d.append('bla')
     self.assertRaises(RuntimeError, d._finish)
     d.lock()
     self.assertRaises(RuntimeError, d._finish)
     self.assertRaises(RuntimeError, d.lock)
     self.assertRaises(RuntimeError, d.append, d1)
     self.assertFalse(d.called)
     d2.callback('first')
     self.assertFalse(d.called)
     d1.callback('second')
     self.assertTrue(d.called)
     self.assertEqual(d.result,['second', 'first', 'bla'])
示例#6
0
 def test_getbench(self):
     c = self.client
     yield MultiDeferred((c.get(self.uri) for _ in range(1))).lock()