From 926ad3c1a69074b2905d9ef03e639db6ba8d6865 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 10 Nov 2020 11:56:31 +0100 Subject: [PATCH] Bug 25514: Try to fix random failure from REST/Plugin/Objects.t It's causing a "Premature connection close" error https://docs.mojolicious.org/Mojolicious/Guides/FAQ#What-does-Premature-connection-close-mean This is just a guess but maybe it would help to have the Test::Mojo object initiated just before the get? Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/REST/Plugin/Objects.t | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index d5db5e7c66..cbec228ce9 100755 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -84,8 +84,6 @@ use t::lib::Mocks; use t::lib::TestBuilder; use Koha::Database; -my $t = Test::Mojo->new; - my $schema = Koha::Database->new()->schema(); my $builder = t::lib::TestBuilder->new; @@ -119,6 +117,7 @@ subtest 'objects.search helper' => sub { } }); + my $t = Test::Mojo->new; $t->get_ok('/cities?name=manuel&_per_page=1&_page=1') ->status_is(200) ->header_like( 'Link' => qr/; rel="next",/ ) @@ -219,6 +218,7 @@ subtest 'objects.search helper, sorting on mapped column' => sub { $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } }); + my $t = Test::Mojo->new; $t->get_ok('/cities?_order_by=%2Bname&_order_by=+country') ->status_is(200) ->json_has('/0') @@ -249,6 +249,7 @@ subtest 'objects.search helper, encoding' => sub { $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => '❤Argentina❤' } }); + my $t = Test::Mojo->new; $t->get_ok('/cities?q={"country": "❤Argentina❤"}') ->status_is(200) ->json_has('/0') @@ -266,6 +267,7 @@ subtest 'objects.search helper, embed' => sub { my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + my $t = Test::Mojo->new; $t->get_ok('/orders?order_id=' . $order->ordernumber) ->json_is('/0',$order->to_api({ embed => ( { fund => {} } ) })); @@ -290,6 +292,7 @@ subtest 'objects.search helper, with path parameters and _match' => sub { } ); + my $t = Test::Mojo->new; $t->get_ok('/patrons/1/holds?_match=exact') ->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=exact'); @@ -319,6 +322,7 @@ subtest 'object.search helper with query parameter' => sub { my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); + my $t = Test::Mojo->new; $t->get_ok('/biblios' => json => {"suggestions.suggester.patron_id" => $patron1->borrowernumber }) ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); @@ -342,6 +346,7 @@ subtest 'object.search helper with q parameter' => sub { my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); + my $t = Test::Mojo->new; $t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}') ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); @@ -365,6 +370,7 @@ subtest 'object.search helper with x-koha-query header' => sub { my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); + my $t = Test::Mojo->new; $t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'}) ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); @@ -388,6 +394,7 @@ subtest 'object.search helper with all query methods' => sub { my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); + my $t = Test::Mojo->new; $t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron1->cardnumber}) ->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); @@ -410,6 +417,7 @@ subtest 'object.search helper order by embedded columns' => sub { my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); + my $t = Test::Mojo->new; $t->get_ok('/biblios?_order_by=-suggestions.suggester.firstname' => json => [{"me.biblio_id" => $biblio1->biblionumber}, {"me.biblio_id" => $biblio2->biblionumber}]) ->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first') ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); -- 2.39.5