import FCGI-ProcManager 0.12 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
4ceac1a1 8# $Id: procmanager.t,v 1.3 2000/12/10 01:48:58 muaddib Exp $
0baf5fac 9
10use strict;
11use Test;
12
13BEGIN { plan tests => 8; }
14
15use FCGI::ProcManager;
16
17my $m;
18
19ok $m = FCGI::ProcManager->new();
20ok $m->state() eq "idle";
21
22ok $m->n_processes(100) == 100;
23ok $m->n_processes(2) == 2;
24ok $m->n_processes(0) == 0;
25
4ceac1a1 26ok $m->pm_manage();
0baf5fac 27ok $m->want_to_die(1);
28
29# i'm not sure how to test these
4ceac1a1 30#eval { $m->pm_manage(); };
0baf5fac 31#ok $@ =~ /dying from death request/;
32#undef $@;
33
34ok $m->want_to_die(0) == 0;
35
36#ok $m->n_processes(-3);
4ceac1a1 37#eval { $m->pm_manage(); };
0baf5fac 38#ok $@ =~ /dying from number of processes exception: -3/;
39#undef $@;
40
41$m->n_processes(1);
42
4ceac1a1 43#$m->pm_manage();
0baf5fac 44#sample_handler($m);
45
46exit 0;
47
48sub sample_handler {
49 my ($m) = @_;
50
51 while (1) {
52 $m->state("handling");
53
54 # Simulate a request dispatch.
55 my $t = int(rand(6)+10);
56 print "$$ sleeping $t..\n";
57 while (my $nslept = sleep $t) {
58 $t -= $nslept;
59 last unless $t;
60 }
61
62 $m->want_to_die()
63 and $m->exit("Process $$ dying from SIGTERM after cleanup.\n");
64 $m->state("idle");
65
66 # Simulate blocking for a request.
67 my $t1 = int(rand(5)+3);
68 print "$$ waiting for $t1..\n";
69 sleep $t1;
70 }
71}