[Bug 44321] New: t/db_dependent/www/search_utf8.t fails intermittently with Elasticsearch
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Bug ID: 44321 Summary: t/db_dependent/www/search_utf8.t fails intermittently with Elasticsearch Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Test Suite Assignee: chris@bigballofwax.co.nz Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Target Milestone: --- t/db_dependent/www/search_utf8.t fails intermittently when run with Elasticsearch 8, for example the "UTF-8 chars are correctly present. Good" checks at lines 161 and 187 on Koha_Main_D13 #2418 and Koha_Main_D12 #4085 (24-25 Nov 2026). Locally on a fresh KTD with ES8 the first run after boot failed 6 checks (all three record blocks); subsequent runs passed, including one with the ES indexer deliberately paused for 16 seconds. Not reproduced since, so the cause is unconfirmed. Suspected cause: after staging and importing, indexing is done by a separate polled background job (update_elastic_index, es_indexer_daemon.pl), but t::lib::Mocks::Zebra::load_records_ui only does "sleep 10". Polling can add up to 10 seconds for the import job and up to 10 more for the indexing job. Possible fix: when SearchEngine is Elasticsearch, wait for the marc_import_commit_batch and update_elastic_index jobs to finish instead of sleeping. Test plan: 1. ktd --search-engine es8 up, then: prove -v t/db_dependent/www/search_utf8.t 2. Repeat several times, including straight after starting KTD, and under load. 3. All checks should pass every time. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|chris@bigballofwax.co.nz |jonathan.druart@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pedro.amorim@openfifth.co.u | |k -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #1 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 212778 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212778&action=edit Bug 44321: Delete the imported records in t::lib::Mocks::Zebra::clean_records clean_records did not delete anything: - it used a new Test::WWW::Mechanize agent that was not logged in, so every request returned the login page (and get_ok passed), - it deleted the biblio with a GET op=delete, which addbiblio.pl ignores since the CSRF changes (only POST op=cud-delete deletes), - it only handled the first record of the batch. The records imported by t/db_dependent/www/search_utf8.t were then left in the catalog and in the search index, and the searches of the next runs found them. Only the first run on a fresh database really tested that the newly imported records were indexed. Reuse the logged in agent from load_records_ui, delete every imported biblio with a POST op=cud-delete and test that the batch is cleaned and the biblios are deleted. Test plan: 1. Note the number of biblios: SELECT COUNT(*) FROM biblio; 2. prove -v t/db_dependent/www/search_utf8.t (KOHA_INTRANET_URL and KOHA_OPAC_URL must be set) 3. Without the patch the number of biblios increases by 6 at each run, with the patch it does not change and the tests pass Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #2 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 212779 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212779&action=edit Bug 44321: Wait for indexing jobs in search_utf8.t with Elasticsearch t/db_dependent/www/search_utf8.t fails intermittently with Elasticsearch 8 ("UTF-8 chars are correctly present. Good"). After importing a staged batch, t::lib::Mocks::Zebra::load_records_ui only sleeps 10 seconds. With Elasticsearch, indexing is done by background jobs: marc_import_commit_batch, which then enqueues update_elastic_index, picked up by es_indexer_daemon.pl. When the workers poll the database, each job can wait up to 10 seconds before being picked up; on KTD update_elastic_index started 17-28 seconds after being enqueued, so the records were often searched before they were indexed. When SearchEngine is Elasticsearch, wait for those jobs to finish (timeout 120 seconds), then give Elasticsearch 2 seconds to refresh the index. Zebra keeps the existing sleep. Test plan: 1. ktd --search-engine es8 up 2. prove -v t/db_dependent/www/search_utf8.t (KOHA_INTRANET_URL and KOHA_OPAC_URL must be set) 3. Repeat several times, including straight after starting KTD and under load 4. All checks pass every time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #3 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- I tested both patches on a CI-like instance (Debian 13, MariaDB 11.8, Elasticsearch 8) starting from a state with no leftover records from earlier runs, with an empty background job queue. Without the patches: t/db_dependent/www/search_utf8.t fails tests 19, 25, 45, 51, 71 and 77 (all three record blocks), and each run leaves 6 biblios behind (414 -> 420). With both patches: the test passes on two consecutive runs and the number of biblios stays at 414. This also explains why the test seemed to pass on repeated runs: with the old clean_records the imported records stayed in the catalog and the index, so later runs found them. Only the first run on a clean state really tested indexing. Notes, none blocking: 1. clean_records: if no matched_biblionumber is found, search({ biblionumber => [] })->count == 0 is trivially true, so the "imported biblios deleted" test would pass without deleting anything. Consider testing that the list is not empty. 2. clean_records now needs load_records_ui to have run first (it uses $self->{agent}); worth a line in the POD. 3. _wait_for_jobs only calls diag on timeout, so a stuck queue shows up as a later, misleading failure. Consider failing there. 4. The fixed "sleep 2" for the Elasticsearch refresh is still a guess. An explicit refresh of the index would make it deterministic. 5. Only the Elasticsearch path was tested; the Zebra path (sleep 10) is unchanged. Still unexplained: why Jenkins only fails tests 71 and 77 and not all six. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Sponsorship status|--- |Unsponsored Status|Needs Signoff |Signed Off Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212778|0 |1 is obsolete| | Attachment #212779|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #4 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 212836 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212836&action=edit Bug 44321: Delete the imported records in t::lib::Mocks::Zebra::clean_records clean_records did not delete anything: - it used a new Test::WWW::Mechanize agent that was not logged in, so every request returned the login page (and get_ok passed), - it deleted the biblio with a GET op=delete, which addbiblio.pl ignores since the CSRF changes (only POST op=cud-delete deletes), - it only handled the first record of the batch. The records imported by t/db_dependent/www/search_utf8.t were then left in the catalog and in the search index, and the searches of the next runs found them. Only the first run on a fresh database really tested that the newly imported records were indexed. Reuse the logged in agent from load_records_ui, delete every imported biblio with a POST op=cud-delete and test that the batch is cleaned and the biblios are deleted. Test plan: 1. Note the number of biblios: SELECT COUNT(*) FROM biblio; 2. prove -v t/db_dependent/www/search_utf8.t (KOHA_INTRANET_URL and KOHA_OPAC_URL must be set) 3. Without the patch the number of biblios increases by 6 at each run, with the patch it does not change and the tests pass Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 212837 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212837&action=edit Bug 44321: Wait for indexing jobs in search_utf8.t with Elasticsearch t/db_dependent/www/search_utf8.t fails intermittently with Elasticsearch 8 ("UTF-8 chars are correctly present. Good"). After importing a staged batch, t::lib::Mocks::Zebra::load_records_ui only sleeps 10 seconds. With Elasticsearch, indexing is done by background jobs: marc_import_commit_batch, which then enqueues update_elastic_index, picked up by es_indexer_daemon.pl. When the workers poll the database, each job can wait up to 10 seconds before being picked up; on KTD update_elastic_index started 17-28 seconds after being enqueued, so the records were often searched before they were indexed. When SearchEngine is Elasticsearch, wait for those jobs to finish (timeout 120 seconds), then give Elasticsearch 2 seconds to refresh the index. Zebra keeps the existing sleep. Test plan: 1. ktd --search-engine es8 up 2. prove -v t/db_dependent/www/search_utf8.t (KOHA_INTRANET_URL and KOHA_OPAC_URL must be set) 3. Repeat several times, including straight after starting KTD and under load 4. All checks pass every time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 212838 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212838&action=edit Bug 44321: (follow-up) Add t::lib::Wait and wait for the outcome, not a delay The previous patch waits for the import and indexing job rows and then sleeps 2 seconds for Elasticsearch to refresh. Both are proxies: a job row says nothing about the documents being searchable, the sleep is a guess at the refresh interval, a timeout only logged a diag so a stuck queue showed up as a later, misleading failure, and the Zebra path still just slept 10 seconds. Add t::lib::Wait with reusable helpers that poll for the outcome and die with a message saying what was waited for: - wait_until( $description, $condition, $timeout ) - wait_for_job( $job_or_id ): waits for the job to finish, dies straight away if it failed or was cancelled - wait_for_index( \@biblionumbers ): waits until the biblios can be found in the search index of the engine in use. Elasticsearch: refreshes the index and counts the documents by id. Zebra: searches for Local-number Use them in load_records_ui for both search engines instead of the sleeps. Test plan: 1. ktd --search-engine es8 up 2. prove -v t/db_dependent/www/search_utf8.t (KOHA_INTRANET_URL and KOHA_OPAC_URL must be set) 3. Repeat several times, including straight after starting KTD and under load, and with the Elasticsearch indexer slowed down (e.g. pause es_indexer_daemon.pl for 30 seconds after each import) 4. All checks pass every time 5. Set SearchEngine to Zebra (Administration > System preferences) and run the test again: it passes too 6. Stop es_indexer_daemon.pl and run the test with Elasticsearch: it dies after 120 seconds with "Timed out after 120s waiting for ... to be searchable" Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44321 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Thanks Jonathan, This looked good and gave me the idea to generalise it for future uses where we're waiting on background job results, indexing or other slow running tasks. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org