import FCGI-ProcManager 0.16 from CPAN
[catagits/FCGI-ProcManager.git] / t / procmanager.t
index 436a2a8..b0f21eb 100644 (file)
@@ -5,67 +5,58 @@
 # General Public License, Version 2.1, a copy of which can be
 # found in the "COPYING" file of this distribution.
 
-# $Id: procmanager.t,v 1.2 2000/11/10 01:09:48 muaddib Exp $
+# $Id: procmanager.t,v 1.8 2001/02/09 16:16:13 muaddie Exp $
 
 use strict;
 use Test;
 
-BEGIN { plan tests => 8; }
+BEGIN { plan tests => 5; }
 
 use FCGI::ProcManager;
 
 my $m;
 
 ok $m = FCGI::ProcManager->new();
-ok $m->state() eq "idle";
 
 ok $m->n_processes(100) == 100;
 ok $m->n_processes(2) == 2;
 ok $m->n_processes(0) == 0;
 
-ok $m->manage();
-ok $m->want_to_die(1);
-
-# i'm not sure how to test these
-#eval { $m->manage(); };
-#ok $@ =~ /dying from death request/;
-#undef $@;
-
-ok $m->want_to_die(0) == 0;
+ok $m->pm_manage();
 
 #ok $m->n_processes(-3);
-#eval { $m->manage(); };
+#eval { $m->pm_manage(); };
 #ok $@ =~ /dying from number of processes exception: -3/;
 #undef $@;
 
-$m->n_processes(1);
-
-#$m->manage();
-#sample_handler($m);
+if ($ENV{PM_N_PROCESSES}) {
+  $m->n_processes($ENV{PM_N_PROCESSES});
+  $m->pm_manage();
+  sample_request_loop($m);
+}
 
 exit 0;
 
-sub sample_handler {
+sub sample_request_loop {
   my ($m) = @_;
 
   while (1) {
-    $m->state("handling");
+    # Simulate blocking for a request.
+    my $t1 = int(rand(2)+2);
+    print "TEST: simulating blocking for request: $t1 seconds.\n";
+    sleep $t1;
+    # (Here is where accept-fail-on-intr would exit request loop.)
+
+    $m->pm_pre_dispatch();
 
     # Simulate a request dispatch.
-    my $t = int(rand(6)+10);
-    print "$$ sleeping $t..\n";
+    my $t = int(rand(3)+2);
+    print "TEST: simulating new request: $t seconds.\n";
     while (my $nslept = sleep $t) {
       $t -= $nslept;
       last unless $t;
     }
 
-    $m->want_to_die() 
-      and $m->exit("Process $$ dying from SIGTERM after cleanup.\n");
-    $m->state("idle");
-
-    # Simulate blocking for a request.
-    my $t1 = int(rand(5)+3);
-    print "$$ waiting for $t1..\n";
-    sleep $t1;
+    $m->pm_post_dispatch();
   }
 }