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>
This commit is contained in:
parent
5793a29221
commit
29f399f1f8
2 changed files with 31 additions and 1 deletions
|
@ -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
Executable file
17
t/Koha/wait.pl
Executable file
|
@ -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…
Reference in a new issue