def test_clean_connection(self): pool = None pooled = PooledHTTPConnection(self.netloc, self.scheme) conn = pooled.acquire() pool = pooled._pool self.assertTrue(pool is not None) pooled.release() self.assertTrue(pooled._pool is False) poolset = pool._set self.assertEqual(len(poolset), 1) pooled_conn = list(poolset)[0] self.assertTrue(pooled_conn is conn)
def test_dirty_connection(self): pooled = PooledHTTPConnection(self.netloc, self.scheme) conn = pooled.acquire() pool = pooled._pool conn.request("GET", "/") serversock, addr = self.sock.accept() serversock.send("HTTP/1.1 200 OK\n" "Content-Length: 6\n" "\n" "HELLO\n") time.sleep(0.3) # We would read this message like this #resp = conn.getresponse() # but we won't so the connection is dirty pooled.release() poolset = pool._set self.assertEqual(len(poolset), 0)
def test_double_release(self): pooled = PooledHTTPConnection(self.netloc, self.scheme) pooled.acquire() pool = pooled._pool cached_pool = _http_pools[(self.scheme, self.netloc)] self.assertTrue(pooled._pool is cached_pool) pooled.release() poolsize = len(pool._set) if PooledHTTPConnection._pool_disable_after_release: self.assertTrue(pooled._pool is False) if not PooledHTTPConnection._pool_ignore_double_release: with self.assertRaises(AssertionError): pooled.release() else: pooled.release() self.assertEqual(poolsize, len(pool._set))
def test_double_release(self): pooled = PooledHTTPConnection(self.netloc, self.scheme, pool_key='test_key') pooled.acquire() pool = pooled._pool cached_pool = _http_pools[("test_key", self.scheme, self.netloc)] self.assertTrue(pooled._pool is cached_pool) pooled.release() poolsize = len(pool._set) if PooledHTTPConnection._pool_disable_after_release: self.assertTrue(pooled._pool is False) if not PooledHTTPConnection._pool_ignore_double_release: with self.assertRaises(AssertionError): pooled.release() else: pooled.release() self.assertEqual(poolsize, len(pool._set))