Blame t/04_notify.t

Packit 549706
#!/usr/bin/perl
Packit 549706
Packit 549706
# Load testing for prefork.pm
Packit 549706
Packit 549706
use strict;
Packit 549706
BEGIN {
Packit 549706
	$|  = 1;
Packit 549706
	$^W = 1;
Packit 549706
}
Packit 549706
use Test::More tests => 19;
Packit 549706
Packit 549706
use prefork ();
Packit 549706
ok( ! $prefork::FORKING, '$FORKING is false' );
Packit 549706
Packit 549706
# Prepare the things we need
Packit 549706
my $notify1 = 0;
Packit 549706
my $notify2 = 0;
Packit 549706
sub _notify1 { $notify1++ }
Packit 549706
sub _notify2 { $notify2++ }
Packit 549706
Packit 549706
# Start with some bad notify calls
Packit 549706
eval { prefork::notify(undef) };
Packit 549706
ok( $@, 'prefork::notify(undef) dies' );
Packit 549706
ok( $@ =~ /prefork::notify was not passed a CODE reference/, 'die message matches expected' );
Packit 549706
eval { prefork::notify('foo') };
Packit 549706
ok( $@, 'prefork::notify("foo") dies' );
Packit 549706
ok( $@ =~ /prefork::notify was not passed a CODE reference/, 'die message matches expected' );
Packit 549706
eval { prefork::notify(\"foo") };
Packit 549706
ok( $@, 'prefork::notify(\"foo") dies' );
Packit 549706
ok( $@ =~ /prefork::notify was not passed a CODE reference/, 'die message matches expected' );
Packit 549706
Packit 549706
# Give notify the valid function ref
Packit 549706
ok( prefork::notify( \&_notify1 ), 'prefork::notify(\&func) returns true' );
Packit 549706
is( $notify1, 0, 'prefork::notify in non-FORKING context does not call callback' );
Packit 549706
eval { prefork::notify(\&_notify1) };
Packit 549706
ok( $@, 'Duplicate prefork::notify(\&func) call dies' );
Packit 549706
ok( $@ =~ /Callback function already registered/, 'die message matches expected' );
Packit 549706
Packit 549706
# Call ->enable and see if the callback is called
Packit 549706
ok( prefork::enable(), 'prefork::enable returns true' );
Packit 549706
is( $notify1, 1, 'Callback appears to be executed correctly' );
Packit 549706
ok( prefork::enable(), 'prefork::enable returns true' );
Packit 549706
is( $notify1, 1, 'Callback is not called again' );
Packit 549706
Packit 549706
# Pass the second callback, which should be called immediately
Packit 549706
ok( prefork::notify( \&_notify2 ), 'prefork::notify(\&func2) returns true' );
Packit 549706
is( $notify2, 1, 'prefork::notify in FORKING context does call callback' );
Packit 549706
ok( prefork::notify( \&_notify2 ), 'prefork::notify(\&func2) returns true' );
Packit 549706
is( $notify2, 2, 'prefork::notify in FORKING context calls callback again' );