]> git.openstreetmap.org Git - nominatim.git/commitdiff
correctly close API objects during testing
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 5 Dec 2023 20:20:57 +0000 (21:20 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 7 Dec 2023 08:31:00 +0000 (09:31 +0100)
nominatim/tools/convert_sqlite.py
test/python/api/conftest.py

index 0702e5d8c045185cbcfea0a0fd18e328de2cd8b2..16f51b661a6f5849df2c6bd875c76cdc7bb3e025 100644 (file)
@@ -29,9 +29,12 @@ async def convert(project_dir: Path, outfile: Path, options: Set[str]) -> None:
         outapi = napi.NominatimAPIAsync(project_dir,
                                         {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}"})
 
-        async with api.begin() as src, outapi.begin() as dest:
-            writer = SqliteWriter(src, dest, options)
-            await writer.write()
+        try:
+            async with api.begin() as src, outapi.begin() as dest:
+                writer = SqliteWriter(src, dest, options)
+                await writer.write()
+        finally:
+            await outapi.close()
     finally:
         await api.close()
 
index 8f0604d4076c10b8a06c1f2405d3b12f49873f78..91a3107fbcc3cc6692d5a3a515c4cf908f951dff 100644 (file)
@@ -190,18 +190,24 @@ def apiobj(temp_db_with_extensions, temp_db_conn, monkeypatch):
 
 @pytest.fixture(params=['postgres_db', 'sqlite_db'])
 def frontend(request, event_loop, tmp_path):
+    testapis = []
     if request.param == 'sqlite_db':
         db = str(tmp_path / 'test_nominatim_python_unittest.sqlite')
 
         def mkapi(apiobj, options={'reverse'}):
             event_loop.run_until_complete(convert_sqlite.convert(Path('/invalid'),
                                                                  db, options))
-            return napi.NominatimAPI(Path('/invalid'),
-                                     {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={db}",
-                                      'NOMINATIM_USE_US_TIGER_DATA': 'yes',
-                                      'NOMINATIM_API_POOL_SIZE': '0'})
+            outapi = napi.NominatimAPI(Path('/invalid'),
+                                       {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={db}",
+                                        'NOMINATIM_USE_US_TIGER_DATA': 'yes'})
+            testapis.append(outapi)
+
+            return outapi
     elif request.param == 'postgres_db':
         def mkapi(apiobj, options=None):
             return apiobj.api
 
-    return mkapi
+    yield mkapi
+
+    for api in testapis:
+        api.close()