MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_dispose_closes_pooled

Method test_dispose_closes_pooled

test/engine/test_pool.py:1434–1466  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1432 eq_(canary, [1, 1, 2, 2, 2, 2, 2])
1433
1434 def test_dispose_closes_pooled(self):
1435 dbapi = MockDBAPI()
1436
1437 p = pool.QueuePool(
1438 creator=dbapi.connect, pool_size=2, timeout=None, max_overflow=0
1439 )
1440 c1 = p.connect()
1441 c2 = p.connect()
1442 c1_con = c1.dbapi_connection
1443 c2_con = c2.dbapi_connection
1444
1445 c1.close()
1446
1447 eq_(c1_con.close.call_count, 0)
1448 eq_(c2_con.close.call_count, 0)
1449
1450 p.dispose()
1451
1452 eq_(c1_con.close.call_count, 1)
1453 eq_(c2_con.close.call_count, 0)
1454
1455 # currently, if a ConnectionFairy is closed
1456 # after the pool has been disposed, there's no
1457 # flag that states it should be invalidated
1458 # immediately - it just gets returned to the
1459 # pool normally...
1460 c2.close()
1461 eq_(c1_con.close.call_count, 1)
1462 eq_(c2_con.close.call_count, 0)
1463
1464 # ...and that's the one we'll get back next.
1465 c3 = p.connect()
1466 assert c3.dbapi_connection is c2_con
1467
1468 @testing.requires.threading_with_mock
1469 @testing.requires.timing_intensive

Callers

nothing calls this directly

Calls 5

disposeMethod · 0.95
eq_Function · 0.90
MockDBAPIFunction · 0.70
connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected