From 29f399f1f8608310172b8f6963ad79a077783225 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 13 Apr 2020 08:43:10 -0300 Subject: [PATCH] Bug 25109: Add 'wait' tests This simple patch introduces a test for the lock waiting scenario. It replicates the previous tests, but calls a script that passes the wait => 1 parameter to ->lock_exec. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- t/Koha/Script.t | 15 ++++++++++++++- t/Koha/wait.pl | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 t/Koha/wait.pl diff --git a/t/Koha/Script.t b/t/Koha/Script.t index b5853282e8..c15432df61 100644 --- a/t/Koha/Script.t +++ b/t/Koha/Script.t @@ -48,7 +48,8 @@ my $interface = C4::Context->interface; is( $interface, 'commandline', "Context interface set correctly with no flags" ); subtest 'lock_exec() tests' => sub { - plan tests => 2; + + plan tests => 3; # Launch the sleep script my $pid = fork(); @@ -63,6 +64,18 @@ subtest 'lock_exec() tests' => sub { like( $result, qr{Unable to acquire the lock.*}, 'Exception found' ); + $pid = fork(); + if ( $pid == 0 ) { + system( dirname(__FILE__) . '/sleep.pl 2>&1' ); + exit; + } + + sleep 1; # Make sure we start after the fork + $command = dirname(__FILE__) . '/wait.pl'; + $result = `$command 2>&1`; + + is( $result, 'YAY!', 'wait.pl successfully waits for the lock' ); + throws_ok { Koha::Script->new({ lock_name => 'blah' }); } 'Koha::Exceptions::MissingParameter', diff --git a/t/Koha/wait.pl b/t/Koha/wait.pl new file mode 100755 index 0000000000..f909cb1f06 --- /dev/null +++ b/t/Koha/wait.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Koha::Script; +use Fcntl qw(:flock); +use Try::Tiny; + +# # Lock execution +my $script = Koha::Script->new({ script => 'sleep.pl' }); + +$script->lock_exec({ wait => 1 }); + +print STDOUT "YAY!"; + +# Normal exit +1; -- 2.39.5