From 25557e5f14734aa597dbe32293be25d2c539531c Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 5 Jan 2021 15:17:46 +0100 Subject: [PATCH] bdd: factor out reindexing on updates --- test/bdd/steps/nominatim_environment.py | 14 ++++++++++++++ test/bdd/steps/steps_db_ops.py | 16 ++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/test/bdd/steps/nominatim_environment.py b/test/bdd/steps/nominatim_environment.py index 2547bbe2..7013a20e 100644 --- a/test/bdd/steps/nominatim_environment.py +++ b/test/bdd/steps/nominatim_environment.py @@ -191,6 +191,20 @@ class NominatimEnvironment: if not self.keep_scenario_db: self.db_drop_database(self.test_db) + def reindex_placex(self, db): + """ Run the indexing step until all data in the placex has + been processed. Indexing during updates can produce more data + to index under some circumstances. That is why indexing may have + to be run multiple times. + """ + with db.cursor() as cur: + while True: + self.run_update_script('index') + + cur.execute("SELECT 'a' FROM placex WHERE indexed_status != 0 LIMIT 1") + if cur.rowcount == 0: + return + def run_setup_script(self, *args, **kwargs): """ Run the Nominatim setup script with the given arguments. """ diff --git a/test/bdd/steps/steps_db_ops.py b/test/bdd/steps/steps_db_ops.py index 8f20cdaa..6bee88c1 100644 --- a/test/bdd/steps/steps_db_ops.py +++ b/test/bdd/steps/steps_db_ops.py @@ -205,13 +205,7 @@ def update_place_table(context): for row in context.table: PlaceColumn(context).add_row(row, False).db_insert(cur) - while True: - context.nominatim.run_update_script('index') - - cur.execute("SELECT 'a' FROM placex WHERE indexed_status != 0 LIMIT 1") - if cur.rowcount == 0: - break - + context.nominatim.reindex_placex(context.db) check_database_integrity(context) @when("updating postcodes") @@ -227,13 +221,7 @@ def delete_places(context, oids): where, params = NominatimID(oid).table_select() cur.execute("DELETE FROM place WHERE " + where, params) - while True: - context.nominatim.run_update_script('index') - - with context.db.cursor() as cur: - cur.execute("SELECT 'a' FROM placex WHERE indexed_status != 0 LIMIT 1") - if cur.rowcount == 0: - break + context.nominatim.reindex_placex(context.db) ################################ THEN ################################## -- 2.39.5