import FCGI-ProcManager 0.15 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.6 2001/01/31 06:57:28 muaddib Exp $
9
10 use strict;
11 use Test;
12
13 BEGIN { plan tests => 5; }
14
15 use FCGI::ProcManager;
16
17 my $m;
18
19 ok $m = FCGI::ProcManager->new();
20
21 ok $m->n_processes(100) == 100;
22 ok $m->n_processes(2) == 2;
23 ok $m->n_processes(0) == 0;
24
25 ok $m->pm_manage();
26
27 #ok $m->n_processes(-3);
28 #eval { $m->pm_manage(); };
29 #ok $@ =~ /dying from number of processes exception: -3/;
30 #undef $@;
31
32 $m->n_processes(10);
33
34 #$m->pm_manage();
35 #sample_request_loop($m);
36
37 exit 0;
38
39 sub sample_request_loop {
40   my ($m) = @_;
41
42   while (1) {
43     # Simulate blocking for a request.
44     my $t1 = int(rand(2)+2);
45     print "TEST: simulating blocking for request: $t1 seconds.\n";
46     sleep $t1;
47     # (Here is where accept-fail-on-intr would exit request loop.)
48
49     $m->pm_pre_dispatch();
50
51     # Simulate a request dispatch.
52     my $t = int(rand(3)+2);
53     print "TEST: simulating new request: $t seconds.\n";
54     while (my $nslept = sleep $t) {
55       $t -= $nslept;
56       last unless $t;
57     }
58
59     $m->pm_post_dispatch();
60   }
61 }