forked from hans/Nominatim
factor out async connection handling into separate class
Also adds a test for reconnecting regularly while indexing.
This commit is contained in:
@@ -5,7 +5,7 @@ import itertools
|
||||
import psycopg2
|
||||
import pytest
|
||||
|
||||
from nominatim.indexer.indexer import Indexer
|
||||
from nominatim.indexer import indexer
|
||||
|
||||
class IndexerTestDB:
|
||||
|
||||
@@ -111,7 +111,7 @@ def test_index_all_by_rank(test_db, threads):
|
||||
assert 31 == test_db.placex_unindexed()
|
||||
assert 1 == test_db.osmline_unindexed()
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_by_rank(0, 30)
|
||||
|
||||
assert 0 == test_db.placex_unindexed()
|
||||
@@ -150,7 +150,7 @@ def test_index_partial_without_30(test_db, threads):
|
||||
assert 31 == test_db.placex_unindexed()
|
||||
assert 1 == test_db.osmline_unindexed()
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_by_rank(4, 15)
|
||||
|
||||
assert 19 == test_db.placex_unindexed()
|
||||
@@ -170,7 +170,7 @@ def test_index_partial_with_30(test_db, threads):
|
||||
assert 31 == test_db.placex_unindexed()
|
||||
assert 1 == test_db.osmline_unindexed()
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_by_rank(28, 30)
|
||||
|
||||
assert 27 == test_db.placex_unindexed()
|
||||
@@ -191,7 +191,7 @@ def test_index_boundaries(test_db, threads):
|
||||
assert 37 == test_db.placex_unindexed()
|
||||
assert 1 == test_db.osmline_unindexed()
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_boundaries(0, 30)
|
||||
|
||||
assert 31 == test_db.placex_unindexed()
|
||||
@@ -209,14 +209,15 @@ def test_index_postcodes(test_db, threads):
|
||||
for postcode in range(32000, 33000):
|
||||
test_db.add_postcode('us', postcode)
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_postcodes()
|
||||
|
||||
assert 0 == test_db.scalar("""SELECT count(*) FROM location_postcode
|
||||
WHERE indexed_status != 0""")
|
||||
|
||||
|
||||
def test_index_full(test_db):
|
||||
@pytest.mark.parametrize("analyse", [True, False])
|
||||
def test_index_full(test_db, analyse):
|
||||
for rank in range(4, 10):
|
||||
test_db.add_admin(rank_address=rank, rank_search=rank)
|
||||
for rank in range(31):
|
||||
@@ -225,10 +226,23 @@ def test_index_full(test_db):
|
||||
for postcode in range(1000):
|
||||
test_db.add_postcode('de', postcode)
|
||||
|
||||
idx = Indexer('dbname=test_nominatim_python_unittest', 4)
|
||||
idx.index_full()
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', 4)
|
||||
idx.index_full(analyse=analyse)
|
||||
|
||||
assert 0 == test_db.placex_unindexed()
|
||||
assert 0 == test_db.osmline_unindexed()
|
||||
assert 0 == test_db.scalar("""SELECT count(*) FROM location_postcode
|
||||
WHERE indexed_status != 0""")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("threads", [1, 15])
|
||||
def test_index_reopen_connection(test_db, threads, monkeypatch):
|
||||
monkeypatch.setattr(indexer.WorkerPool, "REOPEN_CONNECTIONS_AFTER", 15)
|
||||
|
||||
for _ in range(1000):
|
||||
test_db.add_place(rank_address=30, rank_search=30)
|
||||
|
||||
idx = indexer.Indexer('dbname=test_nominatim_python_unittest', threads)
|
||||
idx.index_by_rank(28, 30)
|
||||
|
||||
assert 0 == test_db.placex_unindexed()
|
||||
|
||||
Reference in New Issue
Block a user