Revision 9557ea30 snf-common/synnefo/lib/pool/tests.py

b/snf-common/synnefo/lib/pool/tests.py
58 58
from collections import defaultdict
59 59

  
60 60
from synnefo.lib.pool import ObjectPool, PoolLimitError, PoolVerificationError
61
from synnefo.lib.pool.http import get_http_connection
62
from synnefo.lib.pool.http import _pools as _http_pools
61 63

  
62 64
# Use backported unittest functionality if Python < 2.7
63 65
try:
......
72 74

  
73 75
mutex = Lock()
74 76

  
77

  
75 78
class NumbersPool(ObjectPool):
76 79
    max = 0
77 80

  
......
252 255
        self.numbers._pool_verify = false
253 256
        self.assertRaises(PoolVerificationError, numbers.pool_get)
254 257

  
255
class ThreadSafetyTest(unittest.TestCase):
258

  
259
class ThreadSafetyTestCase(unittest.TestCase):
256 260

  
257 261
    pool_class = NumbersPool
258 262

  
......
286 290
            raise AssertionError("_pool_create() is not thread safe")
287 291

  
288 292

  
293
class TestHTTPConnectionTestCase(unittest.TestCase):
294
    def test_double_close(self):
295
        conn = get_http_connection("127.0.0.1", "http")
296
        self.assertEqual(conn._pool, _http_pools[("http", "127.0.0.1")])
297
        conn.close()
298
        self.assertIsNone(conn._pool)
299
        # This call does nothing, because conn._pool is already None
300
        conn.close()
301
        self.assertIsNone(conn._pool)
302

  
303
    def test_distinct_pools_per_scheme(self):
304
        conn = get_http_connection("127.0.0.1", "http")
305
        pool = conn._pool
306
        self.assertTrue(pool is _http_pools[("http", "127.0.0.1")])
307
        conn.close()
308
        conn2 = get_http_connection("127.0.0.1", "https")
309
        self.assertTrue(conn is not conn2)
310
        self.assertNotEqual(pool, conn2._pool)
311
        self.assertTrue(conn2._pool is _http_pools[("https", "127.0.0.1")])
312
        conn2.close()
313

  
289 314
if __name__ == '__main__':
290 315
    unittest.main()

Also available in: Unified diff