import FCGI-ProcManager 0.14 from CPAN
[catagits/FCGI-ProcManager.git] / t / procmanager.t
1 # -*- perl -*-
2 # Copyright (c) 2000, FundsXpress Financial Network, Inc.
3 # This library is free software released "AS IS WITH ALL FAULTS"
4 # and WITHOUT ANY WARRANTIES under the terms of the GNU Lesser
5 # General Public License, Version 2.1, a copy of which can be
6 # found in the "COPYING" file of this distribution.
7
8 # $Id: procmanager.t,v 1.4 2001/01/13 06:44:35 muaddib Exp $
9
10 use strict;
11 use Test;
12
13 BEGIN { plan tests => 6; }
14
15 use FCGI::ProcManager;
16
17 my $m;
18
19 ok $m = FCGI::ProcManager->new();
20 ok $m->pm_state() eq "idle";
21
22 ok $m->n_processes(100) == 100;
23 ok $m->n_processes(2) == 2;
24 ok $m->n_processes(0) == 0;
25
26 ok $m->pm_manage();
27
28 #ok $m->n_processes(-3);
29 #eval { $m->pm_manage(); };
30 #ok $@ =~ /dying from number of processes exception: -3/;
31 #undef $@;
32
33 $m->n_processes(20);
34
35 #$m->pm_manage();
36 #sample_request_loop($m);
37
38 exit 0;
39
40 sub sample_request_loop {
41   my ($m) = @_;
42
43   while (1) {
44     # Simulate blocking for a request.
45     my $t1 = int(rand(2)+1);
46     print "$$ waiting for $t1..\n";
47     sleep $t1;
48     # (Here is where accept-fail-on-intr would exit request loop.)
49
50     $m->pm_pre_dispatch();
51
52     # Simulate a request dispatch.
53     my $t = int(rand(3)+1);
54     print "$$ sleeping $t..\n";
55     while (my $nslept = sleep $t) {
56       $t -= $nslept;
57       last unless $t;
58     }
59
60     $m->pm_post_dispatch();
61   }
62 }