예제 #1
0
파일: test_queue.py 프로젝트: BeginMan/toro
    def test_multiple_waiters(self):
        # tests that multiple waiters get their results back
        q = toro.Queue()

        @gen.coroutine
        def waiter(q, evt):
            evt.set((yield q.get()))

        sendings = ['1', '2', '3', '4']
        evts = [toro.AsyncResult() for x in sendings]
        for i, x in enumerate(sendings):
            waiter(q, evts[i]) # start task

        @gen.coroutine
        def collect_pending_results():
            results = set()
            for e in evts:
                if e.ready():
                    # Won't block
                    x = yield e.get()
                    results.add(x)
            raise gen.Return(len(results))

        yield q.put(sendings[0])
        yield pause(timedelta(seconds=.01))
        self.assertEqual((yield collect_pending_results()), 1)
        yield q.put(sendings[1])
        yield pause(timedelta(seconds=.01))
        self.assertEqual((yield collect_pending_results()), 2)
        yield q.put(sendings[2])
        yield q.put(sendings[3])
        yield pause(timedelta(seconds=.01))
        self.assertEqual((yield collect_pending_results()), 4)
예제 #2
0
    def test_multiple_waiters(self):
        # tests that multiple waiters get their results back
        q = toro.Queue()

        @gen.coroutine
        def waiter(q, evt):
            evt.set((yield q.get()))

        sendings = ['1', '2', '3', '4']
        evts = [toro.AsyncResult() for x in sendings]
        for i, x in enumerate(sendings):
            waiter(q, evts[i])  # start task

        @gen.coroutine
        def collect_pending_results():
            results = set()
            for e in evts:
                if e.ready():
                    # Won't block
                    x = yield e.get()
                    results.add(x)
            raise gen.Return(len(results))

        yield q.put(sendings[0])
        yield pause(timedelta(seconds=.01))
        self.assertEquals((yield collect_pending_results()), 1)
        yield q.put(sendings[1])
        yield pause(timedelta(seconds=.01))
        self.assertEquals((yield collect_pending_results()), 2)
        yield q.put(sendings[2])
        yield q.put(sendings[3])
        yield pause(timedelta(seconds=.01))
        self.assertEquals((yield collect_pending_results()), 4)
예제 #3
0
파일: test_queue.py 프로젝트: BeginMan/toro
    def test_max_size(self):
        q = toro.Queue(2)
        results = []

        @gen.coroutine
        def putter():
            yield q.put('a')
            results.append('a')
            yield q.put('b')
            results.append('b')
            yield q.put('c')
            results.append('c')

        future = putter()
        yield pause(timedelta(seconds=.01))
        self.assertEqual(results, ['a', 'b'])
        self.assertEqual((yield q.get()), 'a')
        yield pause(timedelta(seconds=.01))
        self.assertEqual(results, ['a', 'b', 'c'])
        self.assertEqual((yield q.get()), 'b')
        self.assertEqual((yield q.get()), 'c')
        yield future
예제 #4
0
    def test_max_size(self):
        q = toro.Queue(2)
        results = []

        @gen.coroutine
        def putter():
            yield q.put('a')
            results.append('a')
            yield q.put('b')
            results.append('b')
            yield q.put('c')
            results.append('c')

        future = putter()
        yield pause(timedelta(seconds=.01))
        self.assertEquals(results, ['a', 'b'])
        self.assertEquals((yield q.get()), 'a')
        yield pause(timedelta(seconds=.01))
        self.assertEquals(results, ['a', 'b', 'c'])
        self.assertEquals((yield q.get()), 'b')
        self.assertEquals((yield q.get()), 'c')
        yield future