From cc80a1e891be6d2c8113b3f614c2c2aea31a19a1 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 1 Aug 2017 15:26:20 +0300 Subject: [PATCH 2/2] Bug 17897: (follow-up) Cleanup after tests Adds rollback to test data in t/db_dependent/Koha/SearchEngine/ElasticSearch.t To test: 1. prove t/db_dependent/Koha/SearchEngine/ElasticSearch.t --- t/db_dependent/Koha/SearchEngine/ElasticSearch.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/ElasticSearch.t b/t/db_dependent/Koha/SearchEngine/ElasticSearch.t index 9f14548872..77c9237c13 100644 --- a/t/db_dependent/Koha/SearchEngine/ElasticSearch.t +++ b/t/db_dependent/Koha/SearchEngine/ElasticSearch.t @@ -21,14 +21,18 @@ use Modern::Perl qw(2014); use utf8; use Test::More; +use Koha::Database; use Koha::SearchEngine::Elasticsearch; use Koha::SearchMappingManager; +my $schema = Koha::Database->schema; subtest "Reset Elasticsearch mappings", \&reset_elasticsearch_mappings; sub reset_elasticsearch_mappings { my ($rv, $mappings, $count, $mapping); + $schema->storage->txn_begin; + ok(1, 'Scenario: Reset Elasticsearch mappings to an empty database'); #There might or might not be any mappings. Whatever the initial status is, make sure we start from empty tables $rv = Koha::SearchMappingManager::flush(); @@ -69,12 +73,16 @@ sub reset_elasticsearch_mappings { $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'}); $count = $mappings->count(); ok($count > 10, 'Then search mapping tables have been populated'); + + $schema->storage->txn_rollback; } subtest "Get Elasticsearch mappings", \&get_search_mappings; sub get_search_mappings { my ($mappings, $mapping); + $schema->storage->txn_begin; + ok(1, 'Scenario: Get a single search mapping by name'); $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ff7-00'}); ok($mappings, 'When a search mappings is fetched'); @@ -91,13 +99,17 @@ sub get_search_mappings { ok(1, 'Scenario: Get all search mappings'); $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios'}); ok($mappings, 'When search mappings are fetched'); - ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)') + ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)'); + + $schema->storage->txn_rollback; } subtest "Add a search mapping", \&add_mapping; sub add_mapping { my ($rv, $mappings, $mapping, $count); + $schema->storage->txn_begin; + ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings"); $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test', label => 'original language', @@ -122,6 +134,8 @@ sub add_mapping { $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ln-test'}); $count = $mappings->count(); is($count, 1, "Then we received only one mapping from the database"); + + $schema->storage->txn_rollback; } done_testing; -- 2.17.1