def test_waiters_that_cancel (self): q = Queue() gt = spawn(do_bail, q) self.assertEquals(gt.wait(), 'timed out') q.put('hi') self.assertEquals(q.get(), 'hi')
def test_waiters_that_cancel(self): q = Queue() gt = spawn(do_bail, q) self.assertEquals(gt.wait(), 'timed out') q.put('hi') self.assertEquals(q.get(), 'hi')
def test_two_bogus_waiters (self): q = Queue() gt1 = spawn(do_bail, q) gt2 = spawn(do_bail, q) sleep(0) q.put('sent') self.assertEquals(gt1.wait(), 'timed out') self.assertEquals(gt2.wait(), 'timed out') self.assertEquals(q.get(), 'sent')
def test_two_bogus_waiters(self): q = Queue() gt1 = spawn(do_bail, q) gt2 = spawn(do_bail, q) sleep(0) q.put('sent') self.assertEquals(gt1.wait(), 'timed out') self.assertEquals(gt2.wait(), 'timed out') self.assertEquals(q.get(), 'sent')
def test_waiting(self): q = Queue() gt1 = spawn(q.get) sleep(0) self.assertEquals(1, q.getting()) q.put('hi') sleep(0) self.assertEquals(0, q.getting()) self.assertEquals('hi', gt1.wait()) self.assertEquals(0, q.getting())
def test_waiting (self): q = Queue() gt1 = spawn(q.get) sleep(0) self.assertEquals(1, q.getting()) q.put('hi') sleep(0) self.assertEquals(0, q.getting()) self.assertEquals('hi', gt1.wait()) self.assertEquals(0, q.getting())
def test_two_waiters_one_dies(self): def waiter(q): return q.get() q = Queue() dying = spawn(do_bail, q) waiting = spawn(waiter, q) sleep(0) q.put('hi') self.assertEquals(dying.wait(), 'timed out') self.assertEquals(waiting.wait(), 'hi')
def test_two_waiters_one_dies (self): def waiter (q): return q.get() q = Queue() dying = spawn(do_bail, q) waiting = spawn(waiter, q) sleep(0) q.put('hi') self.assertEquals(dying.wait(), 'timed out') self.assertEquals(waiting.wait(), 'hi')
def test_resize_down (self): size = 5 q = Queue(5) for i in range(5): q.put(i) self.assertEquals(list(q.queue), range(5)) q.resize(1) sleep(0) self.assertEquals(list(q.queue), range(5))
def test_send_last (self): q = Queue() def waiter (q): self.assertEquals(q.get(), 'hi2') gt = spawn(with_timeout, 0.1, waiter, q) sleep(0) sleep(0) q.put('hi2') gt.wait()
def test_send_last(self): q = Queue() def waiter(q): self.assertEquals(q.get(), 'hi2') gt = spawn(with_timeout, 0.1, waiter, q) sleep(0) sleep(0) q.put('hi2') gt.wait()
def test_resize_down(self): size = 5 q = Queue(5) for i in range(5): q.put(i) self.assertEquals(list(q.queue), range(5)) q.resize(1) sleep(0) self.assertEquals(list(q.queue), range(5))
def test_send_last (self): q = Queue() def waiter (q): timer = Timeout(0.2) self.assertEquals(q.join(), 'hi2') timer.cancel() spawn(waiter, q) sleep(0) sleep(0) q.put('hi2')
def test_send_last(self): q = Queue() def waiter(q): timer = Timeout(0.2) self.assertEquals(q.join(), 'hi2') timer.cancel() spawn(waiter, q) sleep(0) sleep(0) q.put('hi2')
def test_waiting(self): def do_wait(q, evt): result = q.join() evt.send(result) q = Queue() e1 = Event() spawn(do_wait, q, e1) sleep(0) self.assertEquals(1, q.join()) q.put('hi') sleep(0) self.assertEquals(0, q.join()) self.assertEquals('hi', e1.wait()) self.assertEquals(0, q.join())
def test_waiting (self): def do_wait (q, evt): result = q.join() evt.send(result) q = Queue() e1 = Event() spawn(do_wait, q, e1) sleep(0) self.assertEquals(1, q.join()) q.put('hi') sleep(0) self.assertEquals(0, q.join()) self.assertEquals('hi', e1.wait()) self.assertEquals(0, q.join())
def test_channel_send (self): channel = Queue(0) events = [] def another_greenlet (): events.append(channel.get()) events.append(channel.get()) gt = spawn(another_greenlet) events.append('sending') channel.put('hello') events.append('sent hello') channel.put('world') events.append('sent world') self.assertEqual(['sending', 'hello', 'sent hello', 'world', 'sent world'], events)
def test_waiters_that_cancel(self): q = Queue() def do_receive(q, evt): Timeout(0, RuntimeError()) try: result = q.join() evt.send(result) except RuntimeError: evt.send('timed out') evt = Event() spawn(do_receive, q, evt) self.assertEquals(evt.wait(), 'timed out') q.put('hi') self.assertEquals(q.get(), 'hi')
def test_waiters_that_cancel (self): q = Queue() def do_receive (q, evt): Timeout(0, RuntimeError()) try: result = q.join() evt.send(result) except RuntimeError: evt.send('timed out') evt = Event() spawn(do_receive, q, evt) self.assertEquals(evt.wait(), 'timed out') q.put('hi') self.assertEquals(q.get(), 'hi')
def test_channel_send(self): channel = Queue(0) events = [] def another_greenlet(): events.append(channel.get()) events.append(channel.get()) gt = spawn(another_greenlet) events.append('sending') channel.put('hello') events.append('sent hello') channel.put('world') events.append('sent world') self.assertEqual( ['sending', 'hello', 'sent hello', 'world', 'sent world'], events)
def test_two_bogus_waiters (self): def do_receive (q, evt): Timeout(0, RuntimeError()) try: result = q.join() evt.send(result) except RuntimeError: evt.send('timed out') q = Queue() e1 = Event() e2 = Event() spawn(do_receive, q, e1) spawn(do_receive, q, e2) sleep(0) q.put('sent') self.assertEquals(e1.wait(), 'timed out') self.assertEquals(e2.wait(), 'timed out') self.assertEquals(q.get(), 'sent')
def test_two_bogus_waiters(self): def do_receive(q, evt): Timeout(0, RuntimeError()) try: result = q.join() evt.send(result) except RuntimeError: evt.send('timed out') q = Queue() e1 = Event() e2 = Event() spawn(do_receive, q, e1) spawn(do_receive, q, e2) sleep(0) q.put('sent') self.assertEquals(e1.wait(), 'timed out') self.assertEquals(e2.wait(), 'timed out') self.assertEquals(q.get(), 'sent')
def test_multiple_waiters(self): self.reset_timeout(100000000) # tests that multiple waiters get their results back q = Queue() sendings = ['1', '2', '3', '4'] gts = [spawn(q.join) for x in sendings] sleep(0.01) # get 'em all waiting q.put(sendings[0]) q.put(sendings[1]) q.put(sendings[2]) q.put(sendings[3]) results = waitall(*gts) self.assertEquals(sorted(results), sorted(sendings))
def test_multiple_waiters (self): self.reset_timeout(100000000) # tests that multiple waiters get their results back q = Queue() sendings = ['1', '2', '3', '4'] gts = [spawn(q.join) for x in sendings] sleep(0.01) # get 'em all waiting q.put(sendings[0]) q.put(sendings[1]) q.put(sendings[2]) q.put(sendings[3]) results = waitall(*gts) self.assertEquals(sorted(results), sorted(sendings))
def test_two_waiters_one_dies (self): def waiter (q, evt): evt.send(q.join()) def do_receive (q, evt): Timeout(0, RuntimeError()) try: result = q.get() evt.send(result) except RuntimeError: evt.send('timed out') q = Queue() dying_evt = Event() waiting_evt = Event() spawn(do_receive, q, dying_evt) spawn(waiter, q, waiting_evt) sleep(0) q.put('hi') self.assertEquals(dying_evt.wait(), 'timed out') self.assertEquals(waiting_evt.wait(), 'hi')
def test_two_waiters_one_dies(self): def waiter(q, evt): evt.send(q.join()) def do_receive(q, evt): Timeout(0, RuntimeError()) try: result = q.get() evt.send(result) except RuntimeError: evt.send('timed out') q = Queue() dying_evt = Event() waiting_evt = Event() spawn(do_receive, q, dying_evt) spawn(waiter, q, waiting_evt) sleep(0) q.put('hi') self.assertEquals(dying_evt.wait(), 'timed out') self.assertEquals(waiting_evt.wait(), 'hi')
def test_send_first(self): q = Queue() q.put('hi') self.assertEquals(q.get(), 'hi')
def test_send_first (self): q = Queue() q.put('hi') self.assertEquals(q.get(), 'hi')