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