From cde9628b86951209f7c9099ef4907abf29753b82 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 23 Mar 2026 00:21:39 +0100 Subject: [PATCH] Bug 40962: Fix race condition in OAI Server test for OpacHiddenItems The 'Tests for OpacHiddenItems' subtest captured Perl's wall clock time *after* calling build_sample_item(), then used that timestamp as both the expected OAI datestamp and the 'from' filter. On slow systems the INSERT can straddle a second boundary, so MySQL records T:40 while dt_from_string returns T:41, causing noRecordsMatch on the ListRecords tests and a datestamp mismatch on the GetRecord tests. Fix by calling $item->discard_changes and deriving $utc_timestamp from the timestamp MySQL actually assigned, matching the pattern already used in the Bug 19725 subtest in the same file. Signed-off-by: Martin Renvoize --- t/db_dependent/OAI/Server.t | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index 72430aaeba..00b4c2191d 100755 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -589,10 +589,15 @@ subtest 'Tests for OpacHiddenItems' => sub { t::lib::Mocks::mock_preference( 'OAI-PMH:ConfFile' => File::Spec->rel2abs( dirname(__FILE__) ) . '/oaiconf_items.yaml' ); $schema->storage->txn_begin; - my $builder = t::lib::TestBuilder->new; - my $item = $builder->build_sample_item(); - my $biblio = $item->biblio; - my $utc_datetime = dt_from_string( undef, undef, 'UTC' ); + my $builder = t::lib::TestBuilder->new; + my $item = $builder->build_sample_item(); + my $biblio = $item->biblio; + + # Read the timestamp MySQL actually assigned rather than capturing Perl's + # wall clock after the fact — on slow systems the two can differ by 1 second, + # causing the 'from' filter to miss the just-created record. + $item->discard_changes; + my $utc_datetime = dt_from_string( $item->timestamp ); my $utc_timestamp = $utc_datetime->ymd . 'T' . $utc_datetime->hms . 'Z'; my $get_items = {