MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_checkin_event_gc

Method test_checkin_event_gc

test/engine/test_pool.py:760–817  ·  view source on GitHub ↗

tests for #8419, which have been modified for 2.0 in #9237

(
        self, is_asyncio, has_terminate, invalidate_conn_rec
    )

Source from the content-addressed store, hash-verified

758 @testing.variation("has_terminate", [True, False])
759 @testing.variation("invalidate_conn_rec", [True, False])
760 def test_checkin_event_gc(
761 self, is_asyncio, has_terminate, invalidate_conn_rec
762 ):
763 """tests for #8419, which have been modified for 2.0 in #9237"""
764
765 p, canary = self._checkin_event_fixture(
766 _is_asyncio=bool(is_asyncio), _has_terminate=bool(has_terminate)
767 )
768
769 c1 = p.connect()
770
771 dbapi_connection = weakref.ref(c1.dbapi_connection)
772
773 eq_(canary, [])
774
775 if invalidate_conn_rec:
776 # test #10414
777 c1._connection_record.invalidate()
778
779 if is_asyncio and not invalidate_conn_rec:
780 if has_terminate:
781 with expect_warnings(
782 "The garbage collector is trying to clean up.*which will "
783 "be terminated."
784 ):
785 del c1
786 lazy_gc()
787 else:
788 with expect_warnings(
789 "The garbage collector is trying to clean up.*which will "
790 "be dropped, as it cannot be safely terminated."
791 ):
792 del c1
793 lazy_gc()
794 else:
795 del c1
796 lazy_gc()
797
798 detach_gced = is_asyncio
799
800 if invalidate_conn_rec:
801 eq_(canary, ["checkin"])
802 elif detach_gced:
803 if has_terminate:
804 eq_(canary, ["reset_no_rollback", "detach", "close_detached"])
805 else:
806 # "close_detached" is not called because for asyncio without
807 # terminate the connection is just lost.
808 eq_(canary, ["reset_no_rollback", "detach"])
809
810 else:
811 eq_(canary, ["reset_rollback_ok", "checkin"])
812
813 gc_collect()
814 if detach_gced or invalidate_conn_rec:
815 is_none(dbapi_connection())
816 else:
817 is_not_none(dbapi_connection())

Callers

nothing calls this directly

Calls 8

eq_Function · 0.90
expect_warningsFunction · 0.90
lazy_gcFunction · 0.90
is_noneFunction · 0.90
is_not_noneFunction · 0.90
connectMethod · 0.45
invalidateMethod · 0.45

Tested by

no test coverage detected