Bug 37898: Wrap Indexer.t inside a transaction

This tests leave new data on the DB. This patch fixes it.

To test:
1. Run:
   $ ktd --shell
  k$ echo "SELECT COUNT(*) FROM biblio \G" | koha-mysql kohadev
2. Run:
  k$ prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t
=> SUCCESS: Tests pass
3. Repeat 1
=> FAIL: Biblio count raised
4. Apply this patch
5. Repeat 2 and 3
=> SUCCESS: Tests pass
=> SUCCESS: Biblio count remains
6. Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2024-09-11 12:35:17 -03:00 committed by Martin Renvoize
parent 1e3d24e058
commit b41fa9b487
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -41,6 +41,8 @@ SKIP: {
skip 'Elasticsearch configuration not available', 3
if $@;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $biblio =
$builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation
@ -157,9 +159,14 @@ SKIP: {
};
$schema->storage->txn_rollback;
subtest 'update_index' => sub {
plan tests => 1;
$schema->storage->txn_begin;
my $biblio = $builder->build_sample_biblio;
my $biblionumber = $biblio->biblionumber;
$biblio->delete;
@ -171,6 +178,7 @@ SKIP: {
}
"", "update_index called with deleted biblionumber should not crash";
$schema->storage->txn_rollback;
};
}