Browse Source

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 <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Tomas Cohen Arazi 1 year ago
committed by Martin Renvoize
parent
commit
29f399f1f8
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 15
      t/Koha/Script.t
  2. 17
      t/Koha/wait.pl

15
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',

17
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;
Loading…
Cancel
Save