Esempio n. 1
0
    def test_multiple_pool_invocation(self):

        self.pool = ObjectPool(self.klass, min_init=2)
        dpool = ObjectPool(Browser1, min_init=3)

        with self.pool.get() as (item, item_stats):
            t = item.do_work()

        with dpool.get() as (item1, item_stats1):
            t1 = item1.do_work()

        dpool.destroy()
        self.assertNotEqual(t1, t)
 def test_browser(self):
     starting_ff_count = self.get_process_count()
     print(starting_ff_count)
     self.pool = ObjectPool(self.klass, min_init=1, expires=0)
     time.sleep(10)
     after_ff_count = self.get_process_count()
     print(after_ff_count)
     final_count = after_ff_count - starting_ff_count
     self.assertEqual(final_count, 1)
Esempio n. 3
0
    def test_with_expire_false_pre_check(self):
        self.pool = ObjectPool(self.klass, min_init=1, expires=10)

        with self.pool.get() as (item, item_stats):
            t = item_stats['created_at']

        time.sleep(13)

        with self.pool.get() as (item1, item_stats1):
            t1 = item_stats1['created_at']

        self.assertEqual(item1, item)
    def test_browser_without_cloning(self):
        starting_ff_count = self.get_process_count()
        self.pool = ObjectPool(self.klass, min_init=2, expires=0)
        after_ff_count = self.get_process_count()
        final_count = after_ff_count - starting_ff_count

        with self.pool.get() as (browser, browser_stats):
            title = browser.get_page_title('https://www.google.co.in/')

        with self.pool.get() as (browser1, browser_stats):
            title1 = browser1.get_page_title('https://www.facebook.com/')

        self.assertNotEqual(browser, browser1)
Esempio n. 5
0
    def test_with_expire_true_post_check(self):
        self.pool = ObjectPool(self.klass, min_init=1, expires=10)

        with self.pool.get() as (item, item_stats):
            t = item_stats['created_at']

        time.sleep(13)

        with self.pool.get() as (item1, item_stats1):
            t1 = item_stats1['created_at']

        with self.pool.get() as (item2, item_stats2):
            t2 = item_stats2['created_at']

        if item1 is item:
            self.assertNotEqual(item2, item)
        else:
            self.assertEqual(item1, item)
Esempio n. 6
0
    def test_pool_size_growth(self):
        """pool size will grow up to max. This test case is a simulation of
        concurrent access and pool growth"""
        self.pool = ObjectPool(self.klass, min_init=1, max_capacity=1)

        p1, stats = self.pool._get_resource()

        p1_size = self.pool.get_pool_size()

        with self.pool.get() as (item, item_stats):
            t = item.do_work()

        p2_size = self.pool.get_pool_size()

        self.pool._queue_resource(p1, stats)

        p3_size = self.pool.get_pool_size()

        self.assertEqual(p3_size, 1)
Esempio n. 7
0
    def test_pool_with_reusable(self):
        """pool size will grow up to max. This test case is a simulation of
        concurrent access and pool growth"""
        self.pool = ObjectPool(self.klass,
                               min_init=1,
                               max_capacity=1,
                               max_reusable=2)

        with self.pool.get() as (item0, item_stats):
            t = item0.do_work()

        with self.pool.get() as (item, item_stats):
            t = item.do_work()

        with self.pool.get() as (item1, item_stats):
            t = item1.do_work()

        with self.pool.get() as (item2, item_stats):
            t = item2.do_work()

        self.assertEqual(item0, item)
        self.assertNotEqual(item1, item)
        self.assertEqual(item1, item2)
 def test_without_cloning_option(self):
     """resource will be created by cloning the instance"""
     self.pool = ObjectPool(self.klass, min_init=2, cloning=False)
     self.assertEqual(self.pool.get_pool_size(), 2)
 def test_with_lazy_option(self):
     """lazy pool will be created with zero resources upon creation"""
     self.pool = ObjectPool(self.klass, lazy=True)
     self.assertEqual(self.pool.get_pool_size(), 0)
    def test_multiple_pool_creation(self):
        self.pool = ObjectPool(self.klass, min_init=2)
        dpool = ObjectPool(Browser1, min_init=3)

        self.assertNotEqual(self.pool, dpool)
        dpool.destroy()
 def test_with_default_values(self):
     """pool should be created with default values"""
     self.pool = ObjectPool(self.klass)
     self.assertIsNotNone(self.pool)
Esempio n. 12
0
 def test_exists(self):
     """pool become available after it created."""
     self.pool = ObjectPool(self.klass, min_init=1, expires=0)
     exists = ObjectPool.pool_exists(self.klass)
     self.assertTrue(exists)
Esempio n. 13
0
 def test_destroy(self):
     """after destroy, pool should not be available or exist."""
     self.pool = ObjectPool(self.klass, min_init=1, expires=0)
     self.pool.destroy()
     self.assertFalse(ObjectPool.pool_exists(self.klass))
Esempio n. 14
0
 def test_is_full_with_not_same_min_max(self):
     """testing is_pool_full method with max > min_init"""
     self.pool = ObjectPool(self.klass, min_init=1, max_capacity=2)
     self.assertFalse(self.pool.is_pool_full())
Esempio n. 15
0
 def test_is_full_with_same_min_max(self):
     """testing is_pool_full with same min_init and max"""
     self.pool = ObjectPool(self.klass, min_init=2, max_capacity=2)
     self.assertTrue(self.pool.is_pool_full())
 def test_with_max_zero(self):
     """pool size should be same as min_init right after creation"""
     self.pool = ObjectPool(self.klass, min_init=3, max_capacity=0)
     self.assertEqual(self.pool.get_pool_size(), 3)
 def test_creation_same_pool(self):
     """pool size should be same as min_init right after creation"""
     self.pool = ObjectPool(self.klass)
     self.pool1 = ObjectPool(self.klass)
     self.assertEqual(self.pool, self.pool1)
     self.pool1.destroy()
Esempio n. 18
0
 def test_is_full_with_max_zero(self):
     """when max_capacity=0, is_pool_full always return False."""
     self.pool = ObjectPool(self.klass, min_init=3, max_capacity=0)
     self.assertFalse(self.pool.is_pool_full())