Bugzilla – Attachment 160562 Details for
Bug 35086
Koha::SearchEngine::Elasticsearch::Indexer->update_index needs to commit in batches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35086: Tidy tests
Bug-35086-Tidy-tests.patch (text/plain), 10.23 KB, created by
David Nind
on 2024-01-04 21:52:40 UTC
(
hide
)
Description:
Bug 35086: Tidy tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-01-04 21:52:40 UTC
Size:
10.23 KB
patch
obsolete
>From ef22cc97471a1f09b79f06b0841bc722d2595a38 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 4 Jan 2024 12:55:03 +0000 >Subject: [PATCH] Bug 35086: Tidy tests > >Signed-off-by: David Nind <david@davidnind.com> >--- > .../Koha/SearchEngine/Elasticsearch/Indexer.t | 242 ++++++++++-------- > 1 file changed, 129 insertions(+), 113 deletions(-) > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >index 69767bae8e..7dfd0b272b 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >@@ -38,123 +38,139 @@ SKIP: { > > eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; > >- skip 'Elasticsearch configuration not available', 2 >+ skip 'Elasticsearch configuration not available', 3 > if $@; > >-my $builder = t::lib::TestBuilder->new; >-my $biblio = $builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation >- >-subtest 'create_index() tests' => sub { >- plan tests => 6; >- my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); >- $se->mock( '_read_configuration', sub { >- my ($self, $sub ) = @_; >- my $method = $se->original( '_read_configuration' ); >- my $conf = $method->( $self ); >- $conf->{index_name} .= '__test'; >- return $conf; >- }); >- >- my $indexer; >- ok( >- $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }), >- 'Creating a new indexer object' >- ); >- >- is( >- $indexer->create_index(), >- Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(), >- 'Creating an index' >- ); >- >- my $marc_record = MARC::Record->new(); >- $marc_record->append_fields( >- MARC::Field->new('001', '1234567'), >- MARC::Field->new('020', '', '', 'a' => '1234567890123'), >- MARC::Field->new('245', '', '', 'a' => 'Title') >- ); >- my $records = [$marc_record]; >- >- my $response = $indexer->update_index([1], $records); >- is( $response->{errors}, 0, "no error on update_index" ); >- is( scalar(@{$response->{items}}), 1, "1 item indexed" ); >- is( $response->{items}[0]->{index}->{_id},"1", "We should get a string matching the bibnumber passed in"); >- >- is( >- $indexer->drop_index(), >- Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(), >- 'Dropping the index' >- ); >-}; >- >-subtest 'index_records() tests' => sub { >- plan tests => 4; >- my $mock_index = Test::MockModule->new("Koha::SearchEngine::Elasticsearch::Indexer"); >- $mock_index->mock( update_index => sub { >- my ($self, $record_ids, $records) = @_; >- warn "Update " . $record_ids->[0] . $records->[0]->as_usmarc; >- }); >- $mock_index->mock( update_index_background => sub { >- my ($self, $record_ids) = @_; >- warn "Update background " . $record_ids->[0]; >- }); >- >- my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'authorities' }); >- >- my $marc_record = MARC::Record->new(); >- $marc_record->append_fields( >- MARC::Field->new('001', '1234567'), >- MARC::Field->new('100', '', '', 'a' => 'Rosenstock, Jeff'), >- ); >- warning_is { >- $indexer->index_records( [42], 'specialUpdate', 'authorityserver', >- [$marc_record] ); >- } >- "Update 42" . $marc_record->as_usmarc, >- "When passing record and ids to index_records they are correctly passed through to update_index"; >- >- $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }); >- $marc_record = $biblio->metadata->record({ embed_items => 1 }); >- warning_is { >- $indexer->index_records( [ $biblio->biblionumber ], >- 'specialUpdate', 'biblioserver' ); >- } >- "Update background " . $biblio->biblionumber, >- "When passing id only to index_records the marc record is fetched and passed through to update_index"; >- >- my $chunks = 0; >- $mock_index->mock( >- update_index => sub { >- my ( $self, $record_ids, $records ) = @_; >- $chunks++; >+ my $builder = t::lib::TestBuilder->new; >+ my $biblio = >+ $builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation >+ >+ subtest 'create_index() tests' => sub { >+ plan tests => 6; >+ my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); >+ $se->mock( >+ '_read_configuration', >+ sub { >+ my ( $self, $sub ) = @_; >+ my $method = $se->original('_read_configuration'); >+ my $conf = $method->($self); >+ $conf->{index_name} .= '__test'; >+ return $conf; >+ } >+ ); >+ >+ my $indexer; >+ ok( >+ $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { 'index' => 'biblios' } ), >+ 'Creating a new indexer object' >+ ); >+ >+ is( >+ $indexer->create_index(), >+ Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(), >+ 'Creating an index' >+ ); >+ >+ my $marc_record = MARC::Record->new(); >+ $marc_record->append_fields( >+ MARC::Field->new( '001', '1234567' ), >+ MARC::Field->new( '020', '', '', 'a' => '1234567890123' ), >+ MARC::Field->new( '245', '', '', 'a' => 'Title' ) >+ ); >+ my $records = [$marc_record]; >+ >+ my $response = $indexer->update_index( [1], $records ); >+ is( $response->{errors}, 0, "no error on update_index" ); >+ is( scalar( @{ $response->{items} } ), 1, "1 item indexed" ); >+ is( $response->{items}[0]->{index}->{_id}, "1", "We should get a string matching the bibnumber passed in" ); >+ >+ is( >+ $indexer->drop_index(), >+ Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(), >+ 'Dropping the index' >+ ); >+ }; >+ >+ subtest 'index_records() tests' => sub { >+ plan tests => 4; >+ my $mock_index = Test::MockModule->new("Koha::SearchEngine::Elasticsearch::Indexer"); >+ $mock_index->mock( >+ update_index => sub { >+ my ( $self, $record_ids, $records ) = @_; >+ warn "Update " . $record_ids->[0] . $records->[0]->as_usmarc; >+ } >+ ); >+ $mock_index->mock( >+ update_index_background => sub { >+ my ( $self, $record_ids ) = @_; >+ warn "Update background " . $record_ids->[0]; >+ } >+ ); >+ >+ my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { 'index' => 'authorities' } ); >+ >+ my $marc_record = MARC::Record->new(); >+ $marc_record->append_fields( >+ MARC::Field->new( '001', '1234567' ), >+ MARC::Field->new( '100', '', '', 'a' => 'Rosenstock, Jeff' ), >+ ); >+ warning_is { >+ $indexer->index_records( >+ [42], 'specialUpdate', 'authorityserver', >+ [$marc_record] >+ ); > } >- ); >- >- t::lib::Mocks::mock_config( 'elasticsearch', { server => 'false', index_name => 'pseudo' } ); >- my @big_array = 1 .. 10000; >- $indexer->index_records( \@big_array, 'specialUpdate', 'biblioserver', \@big_array ); >- is( $chunks, 2, "We split 10000 records into two chunks when chunk size not set" ); >- >- $chunks = 0; >- t::lib::Mocks::mock_config( 'elasticsearch', { server => 'false', index_name => 'pseudo', chunk_size => 10 } ); >- $indexer->index_records( \@big_array, 'specialUpdate', 'biblioserver', \@big_array ); >- is( $chunks, 1000, "We split 10000 records into 1000 chunks when chunk size is 10" ); >- >-}; >- >-subtest 'update_index' => sub { >- plan tests => 1; >- >- my $biblio = $builder->build_sample_biblio; >- my $biblionumber = $biblio->biblionumber; >- $biblio->delete; >- >- my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }); >- warning_is { >- $indexer->update_index([$biblionumber]); >+ "Update 42" . $marc_record->as_usmarc, >+ "When passing record and ids to index_records they are correctly passed through to update_index"; >+ >+ $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { 'index' => 'biblios' } ); >+ $marc_record = $biblio->metadata->record( { embed_items => 1 } ); >+ warning_is { >+ $indexer->index_records( >+ [ $biblio->biblionumber ], >+ 'specialUpdate', 'biblioserver' >+ ); >+ } >+ "Update background " . $biblio->biblionumber, >+ "When passing id only to index_records the marc record is fetched and passed through to update_index"; >+ >+ my $chunks = 0; >+ $mock_index->mock( >+ update_index => sub { >+ my ( $self, $record_ids, $records ) = @_; >+ $chunks++; >+ } >+ ); >+ >+ t::lib::Mocks::mock_config( 'elasticsearch', { server => 'false', index_name => 'pseudo' } ); >+ my @big_array = 1 .. 10000; >+ $indexer->index_records( \@big_array, 'specialUpdate', 'biblioserver', \@big_array ); >+ is( $chunks, 2, "We split 10000 records into two chunks when chunk size not set" ); >+ >+ $chunks = 0; >+ t::lib::Mocks::mock_config( >+ 'elasticsearch', >+ { server => 'false', index_name => 'pseudo', chunk_size => 10 } >+ ); >+ $indexer->index_records( \@big_array, 'specialUpdate', 'biblioserver', \@big_array ); >+ is( $chunks, 1000, "We split 10000 records into 1000 chunks when chunk size is 10" ); >+ >+ }; >+ >+ subtest 'update_index' => sub { >+ plan tests => 1; >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $biblionumber = $biblio->biblionumber; >+ $biblio->delete; >+ >+ my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { 'index' => 'biblios' } ); >+ warning_is { >+ $indexer->update_index( [$biblionumber] ); > >- } "", "update_index called with deleted biblionumber should not crash"; >+ } >+ "", "update_index called with deleted biblionumber should not crash"; > >-}; >+ }; > > } >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35086
:
160278
|
160301
|
160530
|
160531
|
160532
|
160560
|
160561
|
160562
|
160572
|
160853
|
160854
|
160855
|
160856