Beispiel #1
0
    def test_a_buncha_stuff(self):
        assert_ = self.assert_

        class Dummy(object):
            def foo(self, when, token=None):
                assert_(token is not None)
                time.sleep(random.random() / 200.0)
                return token

        def sender_loop(loopnum):
            obj = tpool.Proxy(Dummy())
            count = 100
            for n in xrange(count):
                sleep(random.random() / 200.0)
                now = time.time()
                token = loopnum * count + n
                rv = obj.foo(now, token=token)
                self.assertEquals(token, rv)
                sleep(random.random() / 200.0)

        cnt = 10
        pile = GreenPile(cnt)
        for i in xrange(cnt):
            pile.spawn(sender_loop, i)
        results = list(pile)
        self.assertEquals(len(results), cnt)
        tpool.killall()
Beispiel #2
0
    def test_a_buncha_stuff (self):
        assert_ = self.assert_

        class Dummy(object):
            def foo (self, when, token = None):
                assert_(token is not None)
                time.sleep(random.random() / 200.0)
                return token

        def sender_loop (loopnum):
            obj = tpool.Proxy(Dummy())
            count = 100
            for n in xrange(count):
                sleep(random.random() / 200.0)
                now = time.time()
                token = loopnum * count + n
                rv = obj.foo(now, token = token)
                self.assertEquals(token, rv)
                sleep(random.random() / 200.0)

        cnt = 10
        pile = GreenPile(cnt)
        for i in xrange(cnt):
            pile.spawn(sender_loop, i)
        results = list(pile)
        self.assertEquals(len(results), cnt)
        tpool.killall()
Beispiel #3
0
    def test_contention (self):
        from tests import test_tpool

        prox = tpool.Proxy(test_tpool)

        pile = GreenPile(4)
        pile.spawn(lambda: self.assertEquals(prox.one, 1))
        pile.spawn(lambda: self.assertEquals(prox.two, 2))
        pile.spawn(lambda: self.assertEquals(prox.three, 3))
        results = list(pile)
        self.assertEquals(len(results), 3)
Beispiel #4
0
 def test_pile_spawn_times_out (self):
     p = GreenPile(4)
     for i in xrange(4):
         p.spawn(passthru, i)
         # now it should be full and this should time out
     Timeout(0)
     self.assertRaises(Timeout, p.spawn, passthru, "time out")
     # verify that the spawn breakage didn't interrupt the sequence
     # and terminates properly
     for i in xrange(4, 10):
         p.spawn(passthru, i)
     self.assertEquals(list(p), list(xrange(10)))
Beispiel #5
0
    def test_constructing_from_pool(self):
        pool = GreenPool(2)
        pile1 = GreenPile(pool)
        pile2 = GreenPile(pool)

        def bunch_of_work(pile, unique):
            for i in xrange(10):
                pile.spawn(passthru, i + unique)

        spawn(bunch_of_work, pile1, 0)
        spawn(bunch_of_work, pile2, 100)
        sleep(0)
        self.assertEquals(list(pile2), list(xrange(100, 110)))
        self.assertEquals(list(pile1), list(xrange(10)))
    def spawn_order_check(self, concurrency):
        # checks that piles are strictly ordered
        p = GreenPile(concurrency)

        def makework(count, unique):
            for i in xrange(count):
                token = (unique, i)
                p.spawn(pressure, token)

        iters = 1000
        spawn(makework, iters, 1)
        spawn(makework, iters, 2)
        spawn(makework, iters, 3)
        p.spawn(pressure, (0, 0))
        latest = [-1] * 4
        received = 0
        it = iter(p)
        while True:
            try:
                i = it.next()
            except StressException, exc:
                i = exc.args[0]
            except StopIteration:
                break
Beispiel #7
0
    def spawn_order_check (self, concurrency):
        # checks that piles are strictly ordered
        p = GreenPile(concurrency)

        def makework (count, unique):
            for i in xrange(count):
                token = (unique, i)
                p.spawn(pressure, token)

        iters = 1000
        spawn(makework, iters, 1)
        spawn(makework, iters, 2)
        spawn(makework, iters, 3)
        p.spawn(pressure, (0, 0))
        latest = [-1] * 4
        received = 0
        it = iter(p)
        while True:
            try:
                i = it.next()
            except StressException, exc:
                i = exc.args[0]
            except StopIteration:
                break
Beispiel #8
0
    def test_contention(self):
        from tests import test_tpool

        prox = tpool.Proxy(test_tpool)

        pile = GreenPile(4)
        pile.spawn(lambda: self.assertEquals(prox.one, 1))
        pile.spawn(lambda: self.assertEquals(prox.two, 2))
        pile.spawn(lambda: self.assertEquals(prox.three, 3))
        results = list(pile)
        self.assertEquals(len(results), 3)
Beispiel #9
0
 def test_pile_spawn_times_out(self):
     p = GreenPile(4)
     for i in xrange(4):
         p.spawn(passthru, i)
         # now it should be full and this should time out
     Timeout(0)
     self.assertRaises(Timeout, p.spawn, passthru, "time out")
     # verify that the spawn breakage didn't interrupt the sequence
     # and terminates properly
     for i in xrange(4, 10):
         p.spawn(passthru, i)
     self.assertEquals(list(p), list(xrange(10)))
Beispiel #10
0
 def test_pile (self):
     p = GreenPile(4)
     for i in xrange(10):
         p.spawn(passthru, i)
     result_list = list(p)
     self.assertEquals(result_list, list(xrange(10)))
Beispiel #11
0
 def test_pile(self):
     p = GreenPile(4)
     for i in xrange(10):
         p.spawn(passthru, i)
     result_list = list(p)
     self.assertEquals(result_list, list(xrange(10)))