MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_reconnect

Method test_reconnect

test/engine/test_reconnect.py:406–468  ·  view source on GitHub ↗

test that an 'is_disconnect' condition will invalidate the connection, and additionally dispose the previous connection pool and recreate.

(self)

Source from the content-addressed store, hash-verified

404 self.dbapi.dispose()
405
406 def test_reconnect(self):
407 """test that an 'is_disconnect' condition will invalidate the
408 connection, and additionally dispose the previous connection
409 pool and recreate."""
410
411 # make a connection
412
413 conn = self.db.connect()
414
415 # connection works
416
417 conn.execute(select(1))
418
419 # create a second connection within the pool, which we'll ensure
420 # also goes away
421
422 conn2 = self.db.connect()
423 conn2.close()
424
425 # two connections opened total now
426
427 assert len(self.dbapi.connections) == 2
428
429 # set it to fail
430
431 self.dbapi.shutdown()
432
433 # force windows monotonic timer to definitely increment
434 time.sleep(0.5)
435
436 # close on DBAPI connection occurs here, as it is detected
437 # as invalid.
438 assert_raises(tsa.exc.DBAPIError, conn.execute, select(1))
439
440 # assert was invalidated
441
442 assert not conn.closed
443 assert conn.invalidated
444
445 # close shouldn't break
446
447 conn.close()
448
449 # ensure one connection closed...
450 eq_(
451 [c.close.mock_calls for c in self.dbapi.connections],
452 [[call()], []],
453 )
454
455 conn = self.db.connect()
456
457 eq_(
458 [c.close.mock_calls for c in self.dbapi.connections],
459 [[call()], [call()], []],
460 )
461
462 conn.execute(select(1))
463 conn.close()

Callers

nothing calls this directly

Calls 8

selectFunction · 0.90
assert_raisesFunction · 0.90
eq_Function · 0.90
callFunction · 0.85
shutdownMethod · 0.80
connectMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected