Bug 41012

Summary: ILSDI_Services.t is failing randomly
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: dcook, lucas
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 40622    
Bug Blocks: 25551    
Attachments: Bug 41012: (bug 40622 follow-up) Clear the MSS cache
Bug 41012: (bug 40622 follow-up) Clear the MSS cache

Description Jonathan Druart 2025-10-14 10:23:56 UTC
Koha_Main_U22/2183

18:58:19 koha-1  |     #   Failed test 'Title hidden in output as expected'
18:58:19 koha-1  |     #   at t/db_dependent/ILSDI_Services.t line 874.
18:58:19 koha-1  |     #          got: '1'
18:58:19 koha-1  |     #     expected: '0'
18:58:19 koha-1  |     # Looks like you failed 1 test of 11.
18:58:19 koha-1  | 
18:58:19 koha-1  | #   Failed test 'GetRecords'
18:58:19 koha-1  | #   at t/db_dependent/ILSDI_Services.t line 923.


 866     my $cgi = CGI->new;
 867     $cgi->param( service => 'GetRecords' );
 868     $cgi->param( id      => $item->biblionumber );
 869 
 870     my $reply = C4::ILSDI::Services::GetRecords($cgi);
 871 
 872     my $opac_marcxml  = $reply->{record}->[0]->{marcxml};
 873     my @title_matches = ( $opac_marcxml =~ m/This is an awesome title/g );
 874     is( scalar @title_matches, 0, 'Title hidden in output as expected' );
Comment 1 Jonathan Druart 2025-10-14 10:27:52 UTC
It's passing locally on U22.
Comment 2 Jonathan Druart 2025-10-15 04:18:37 UTC
I don't understand why the test passes. The marc subfield structure cache is not flushed after we hide the title.
Comment 3 Jonathan Druart 2025-10-15 04:37:07 UTC
Created attachment 187899 [details] [review]
Bug 41012: (bug 40622 follow-up) Clear the MSS cache

For some reasons t/db_dependent/ILSDI_Services.t fails if run after
t/db_dependent/api/v1/biblios.t

When we modify the MARC subfield structure from the tests we must flush
the cache.

Actually I don't understand why the tests are even passing.

I have not tracked down why it only fails when run after t/db_dependent/api/v1/biblios.t

Test plan:
0. Do not apply this patch
1. prove t/db_dependent/api/v1/biblios.t t/db_dependent/ILSDI_Services.t
It fails
    #   Failed test 'Title hidden in output as expected'
    #   at t/db_dependent/ILSDI_Services.t line 874.
    #          got: '1'
    #     expected: '0'
2. Apply this patch, repeat 1.
=> it's green!
Comment 4 David Cook 2025-10-15 04:39:46 UTC
(In reply to Jonathan Druart from comment #2)
> I don't understand why the test passes. The marc subfield structure cache is
> not flushed after we hide the title.

That's a good point.

In KTD, if I run "memcdump -s memcached:11211", I do see a couple of keys...
koha_kohadev::MarcSubfieldStructure-
koha_kohadev::MarcSubfieldStructure-BKS

I wonder if in a fresh KTD if the cache gets populated on the first run of t/db_dependent/ILSDI_Services.t whereas on the CI server it's already been pre-populated I guess I have an idea on how to test that...
Comment 5 David Cook 2025-10-15 04:44:51 UTC
(In reply to David Cook from comment #4)
> In KTD, if I run "memcdump -s memcached:11211", I do see a couple of keys...
> koha_kohadev::MarcSubfieldStructure-
> koha_kohadev::MarcSubfieldStructure-BKS
> 
> I wonder if in a fresh KTD if the cache gets populated on the first run of
> t/db_dependent/ILSDI_Services.t whereas on the CI server it's already been
> pre-populated I guess I have an idea on how to test that...

Admittedly memcdump isn't the best tool. I've found it doesn't already report everything.

But I just tried to add a MARC record in Default Framework and BKS framework via the webapp to pre-prime the caches...

Which gave me these cache keys:
koha_kohadev::MarcSubfieldStructure-
koha_kohadev::MarcStructure-1-BKS
koha_kohadev::MarcStructure-1-

After running t/db_dependent/ILSDI_Services.t, I get the following:
koha_kohadev::MarcStructure-0-
koha_kohadev::MarcStructure-1-
koha_kohadev::MarcStructure-1-BKS
koha_kohadev::MarcSubfieldStructure-

In theory the bibliographic framework used should be the default one...
Comment 6 David Cook 2025-10-15 05:05:41 UTC
So I don't think your patch will help.

And the reason is that you can remove the following lines and the test still passes:

-    my $framework_f245a = Koha::MarcSubfieldStructures->find(
-        { frameworkcode => $biblio->frameworkcode, tagfield => "245", tagsubfield => "a" } );
-    $framework_f245a->hidden('8');
-    $framework_f245a->store();

So there's something else going on here...
Comment 7 David Cook 2025-10-15 05:13:02 UTC
(In reply to David Cook from comment #6)
> So I don't think your patch will help.
> 
> And the reason is that you can remove the following lines and the test still
> passes:
> 
> -    my $framework_f245a = Koha::MarcSubfieldStructures->find(
> -        { frameworkcode => $biblio->frameworkcode, tagfield => "245",
> tagsubfield => "a" } );
> -    $framework_f245a->hidden('8');
> -    $framework_f245a->store();
> 
> So there's something else going on here...

Actually, if I remove those lines, and then re-run it, it will fail...
Comment 8 David Cook 2025-10-15 05:16:24 UTC
I don't care to dig into this one more, so I think I'll just sign off the patch, because in theory it should work.

We should probably have more cache clearing in the unit tests really...
Comment 9 David Cook 2025-10-15 05:17:30 UTC
Created attachment 187900 [details] [review]
Bug 41012: (bug 40622 follow-up) Clear the MSS cache

For some reasons t/db_dependent/ILSDI_Services.t fails if run after
t/db_dependent/api/v1/biblios.t

When we modify the MARC subfield structure from the tests we must flush
the cache.

Actually I don't understand why the tests are even passing.

I have not tracked down why it only fails when run after t/db_dependent/api/v1/biblios.t

Test plan:
0. Do not apply this patch
1. prove t/db_dependent/api/v1/biblios.t t/db_dependent/ILSDI_Services.t
It fails
    #   Failed test 'Title hidden in output as expected'
    #   at t/db_dependent/ILSDI_Services.t line 874.
    #          got: '1'
    #     expected: '0'
2. Apply this patch, repeat 1.
=> it's green!

Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 10 David Cook 2025-10-15 05:19:53 UTC
(In reply to David Cook from comment #7)
> (In reply to David Cook from comment #6)
> > So I don't think your patch will help.
> > 
> > And the reason is that you can remove the following lines and the test still
> > passes:
> > 
> > -    my $framework_f245a = Koha::MarcSubfieldStructures->find(
> > -        { frameworkcode => $biblio->frameworkcode, tagfield => "245",
> > tagsubfield => "a" } );
> > -    $framework_f245a->hidden('8');
> > -    $framework_f245a->store();
> > 
> > So there's something else going on here...
> 
> Actually, if I remove those lines, and then re-run it, it will fail...

Sorry I mean... if I remove those lines, clear the cache, and re-run it, it will fail