Exemple #1
0
    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')
Exemple #2
0
    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')
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
 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())
Exemple #6
0
 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())
Exemple #7
0
    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')
Exemple #8
0
    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')
Exemple #9
0
    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))
Exemple #10
0
    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()
Exemple #11
0
    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()
Exemple #12
0
    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))
Exemple #13
0
    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')
Exemple #14
0
    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')
Exemple #15
0
    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())
Exemple #16
0
    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())
Exemple #17
0
    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)
Exemple #18
0
    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')
Exemple #19
0
    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')
Exemple #20
0
    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)
Exemple #21
0
    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')
Exemple #22
0
    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')
Exemple #23
0
    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))
Exemple #24
0
    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))
Exemple #25
0
    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')
Exemple #26
0
    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')
Exemple #27
0
 def test_send_first(self):
     q = Queue()
     q.put('hi')
     self.assertEquals(q.get(), 'hi')
Exemple #28
0
 def test_send_first (self):
     q = Queue()
     q.put('hi')
     self.assertEquals(q.get(), 'hi')