1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 6;
use FCGI::Engine::ProcManager;
my $m;
ok $m = FCGI::Engine::ProcManager->new();
ok $m->n_processes() == 0;
ok $m->n_processes(100) == 100;
ok $m->n_processes(2) == 2;
ok $m->n_processes(0) == 0;
ok !$m->manage();
#ok $m->n_processes(-3);
#eval { $m->manage(); };
#ok $@ =~ /dying from number of processes exception: -3/;
#undef $@;
if ($ENV{PM_N_PROCESSES}) {
$m->n_processes($ENV{PM_N_PROCESSES});
$m->manage();
sample_request_loop($m);
}
exit 0;
sub sample_request_loop {
my ($m) = @_;
while (1) {
# Simulate blocking for a request.
my $t1 = int(rand(2)+2);
print "TEST: simulating blocking for request: $t1 seconds.\n";
sleep $t1;
# (Here is where accept-fail-on-intr would exit request loop.)
$m->pre_dispatch();
# Simulate a request dispatch.
my $t = int(rand(3)+2);
print "TEST: simulating new request: $t seconds.\n";
while (my $nslept = sleep $t) {
$t -= $nslept;
last unless $t;
}
$m->post_dispatch();
}
}
|