예제 #1
0
파일: test_tpool.py 프로젝트: inercia/evy
    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()
예제 #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()
예제 #3
0
파일: test_tpool.py 프로젝트: inercia/evy
 def test_leakage_from_tracebacks (self):
     tpool.execute(noop)  # get it started
     gc.collect()
     initial_objs = len(gc.get_objects())
     for i in xrange(10):
         self.assertRaises(RuntimeError, tpool.execute, raise_exception)
     gc.collect()
     middle_objs = len(gc.get_objects())
     # some objects will inevitably be created by the previous loop
     # now we test to ensure that running the loop an order of
     # magnitude more doesn't generate additional objects
     for i in xrange(100):
         self.assertRaises(RuntimeError, tpool.execute, raise_exception)
     first_created = middle_objs - initial_objs
     gc.collect()
     second_created = len(gc.get_objects()) - middle_objs
     self.assert_(second_created - first_created < 10,
                  "first loop: %s, second loop: %s" % (first_created, second_created))
     tpool.killall()
예제 #4
0
파일: test_tpool.py 프로젝트: inercia/evy
    def test_benchmark (self):
        """ Benchmark computing the amount of overhead tpool adds to function calls."""
        iterations = 10000
        import timeit

        imports = """
from tests.tpool_test import noop
from evy.tpool import execute
        """
        t = timeit.Timer("noop()", imports)
        results = t.repeat(repeat = 3, number = iterations)
        best_normal = min(results)

        t = timeit.Timer("execute(noop)", imports)
        results = t.repeat(repeat = 3, number = iterations)
        best_tpool = min(results)

        tpool_overhead = (best_tpool - best_normal) / iterations
        print "%s iterations\nTpool overhead is %s seconds per call.  Normal: %s; Tpool: %s" % (
            iterations, tpool_overhead, best_normal, best_tpool)
        tpool.killall()
예제 #5
0
 def test_leakage_from_tracebacks(self):
     tpool.execute(noop)  # get it started
     gc.collect()
     initial_objs = len(gc.get_objects())
     for i in xrange(10):
         self.assertRaises(RuntimeError, tpool.execute, raise_exception)
     gc.collect()
     middle_objs = len(gc.get_objects())
     # some objects will inevitably be created by the previous loop
     # now we test to ensure that running the loop an order of
     # magnitude more doesn't generate additional objects
     for i in xrange(100):
         self.assertRaises(RuntimeError, tpool.execute, raise_exception)
     first_created = middle_objs - initial_objs
     gc.collect()
     second_created = len(gc.get_objects()) - middle_objs
     self.assert_(
         second_created - first_created < 10,
         "first loop: %s, second loop: %s" %
         (first_created, second_created))
     tpool.killall()
예제 #6
0
    def test_benchmark(self):
        """ Benchmark computing the amount of overhead tpool adds to function calls."""
        iterations = 10000
        import timeit

        imports = """
from tests.tpool_test import noop
from evy.tpool import execute
        """
        t = timeit.Timer("noop()", imports)
        results = t.repeat(repeat=3, number=iterations)
        best_normal = min(results)

        t = timeit.Timer("execute(noop)", imports)
        results = t.repeat(repeat=3, number=iterations)
        best_tpool = min(results)

        tpool_overhead = (best_tpool - best_normal) / iterations
        print "%s iterations\nTpool overhead is %s seconds per call.  Normal: %s; Tpool: %s" % (
            iterations, tpool_overhead, best_normal, best_tpool)
        tpool.killall()
예제 #7
0
파일: test_db_pool.py 프로젝트: inercia/evy
    def tearDown (self):
        super(TpoolConnectionPool, self).tearDown()
        from evy import tpool

        tpool.killall()
예제 #8
0
파일: test_tpool.py 프로젝트: inercia/evy
 def tearDown (self):
     tpool.killall()
     super(TestTpool, self).tearDown()
예제 #9
0
파일: test_tpool.py 프로젝트: inercia/evy
 def test_killall (self):
     tpool.killall()
     tpool.setup()
예제 #10
0
    def tearDown(self):
        super(TpoolConnectionPool, self).tearDown()
        from evy import tpool

        tpool.killall()
예제 #11
0
 def tearDown(self):
     tpool.killall()
     super(TestTpool, self).tearDown()
예제 #12
0
 def test_killall(self):
     tpool.killall()
     tpool.setup()