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