From a9d179694aa8b51290928865da7f267ed27e44cc Mon Sep 17 00:00:00 2001
From: Andreas Motl <andreas.motl@crate.io>
Date: Tue, 19 Dec 2023 20:10:36 +0100
Subject: [PATCH] test: Fix `FATAL: sorry, too many clients already`

Within `BasePostgresSDKTests`, new database connections via SQLAlchemy
haven't been closed, and started filling up the connection pool,
eventually saturating it.
---
 target_postgres/tests/test_sdk.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target_postgres/tests/test_sdk.py b/target_postgres/tests/test_sdk.py
index 3f95c393..5d4207ad 100644
--- a/target_postgres/tests/test_sdk.py
+++ b/target_postgres/tests/test_sdk.py
@@ -61,7 +61,9 @@ class BasePostgresSDKTests:
     @pytest.fixture()
     def connection(self, runner):
         engine = create_engine(runner)
-        return engine.connect()
+        with engine.connect() as connection:
+            yield connection
+        engine.dispose()
 
 
 SDKTests = get_target_test_class(