]> granicus.if.org Git - curl/commitdiff
When staring a HTTP server, use the pidfile preferably since it turns out
authorDaniel Stenberg <daniel@haxx.se>
Thu, 28 Apr 2005 13:54:48 +0000 (13:54 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 28 Apr 2005 13:54:48 +0000 (13:54 +0000)
sometimes the server can start but curl cannot speak to it, and then we must
remember the server (in order to kill it properly) anyway.

Also, make sure to kill all servers on exit everywhere.

tests/runtests.pl

index 24041c7d0ee2cb49038c438c336818438c0dbf57..bef5a59a376c30eb89026828287d9f5e048edc69 100755 (executable)
@@ -304,9 +304,6 @@ sub torture {
 
     print "torture OK\n";
     return 0;
-
-    #stopservers();
-    #exit; # for now, we stop after these tests
 }
 
 #######################################################################
@@ -362,7 +359,7 @@ sub runhttpserver {
     my ($verbose, $ipv6) = @_;
     my $RUNNING;
     my $pid;
-
+    my $cmd;
     my $pidfile = $HTTPPIDFILE;
     my $port = $HTTPPORT;
     my $ip = $HOSTIP;
@@ -378,41 +375,44 @@ sub runhttpserver {
 
     $pid = checkserver($pidfile);
 
-    # verify if our/any server is running on this port
-    my $cmd = "$CURL -o log/verifiedserver -g \"http://$ip:$port/verifiedserver\" 2>log/verifyhttp";
-    print "CMD; $cmd\n" if ($verbose);
-    my $res = system($cmd);
+    if($pid <= 0 ) {
 
-    $res >>= 8; # rotate the result
-    my $data;
+        # verify if our/any server is running on this port
+        $cmd = "$CURL -o log/verifiedserver -g \"http://$ip:$port/verifiedserver\" 2>log/verifyhttp";
+        print "CMD; $cmd\n" if ($verbose);
+        my $res = system($cmd);
 
-    if($res && $verbose) {
-        open(ERR, "<log/verifystderr");
-        my @e = <ERR>;
-        close(ERR);
-        print "RUN: curl command returned $res\n";
-        for(@e) {
-            if($_ !~ /^([ \t]*)$/) {
-                print "RUN: $_";
+        $res >>= 8; # rotate the result
+        my $data;
+
+        if($res && $verbose) {
+            open(ERR, "<log/verifystderr");
+            my @e = <ERR>;
+            close(ERR);
+            print "RUN: curl command returned $res\n";
+            for(@e) {
+                if($_ !~ /^([ \t]*)$/) {
+                    print "RUN: $_";
+                }
             }
         }
-    }
-    open(FILE, "<log/verifiedserver");
-    my @file=<FILE>;
-    close(FILE);
-    $data=$file[0]; # first line
+        open(FILE, "<log/verifiedserver");
+        my @file=<FILE>;
+        close(FILE);
+        $data=$file[0]; # first line
 
-    if ( $data =~ /WE ROOLZ: (\d+)/ ) {
-        $pid = 0+$1;
-    }
-    elsif($res == 6) {
-        # curl: (6) Couldn't resolve host '::1'
-        print "RUN: failed to resolve host\n";
-        return -3;
-    }
-    elsif($data || ($res != 7)) {
-        print "RUN: Unknown server is running on port $port\n";
-        return -2;
+        if ( $data =~ /WE ROOLZ: (\d+)/ ) {
+            $pid = 0+$1;
+        }
+        elsif($res == 6) {
+            # curl: (6) Couldn't resolve host '::1'
+            print "RUN: failed to resolve host\n";
+            return -3;
+        }
+        elsif($data || ($res != 7)) {
+            print "RUN: Unknown server is running on port $port\n";
+            return -2;
+        }
     }
 
     if($pid > 0) {
@@ -420,6 +420,7 @@ sub runhttpserver {
         if(!$res) {
             print "RUN: Failed to kill test HTTP$nameext server, do it ",
             "manually and restart the tests.\n";
+            stopservers();
             exit;
         }
         sleep(1);
@@ -441,6 +442,13 @@ sub runhttpserver {
         # verify that our server is up and running:
         my $data=`$CURL --silent -g \"$ip:$port/verifiedserver\" 2>>log/verifyhttp`;
 
+        $pid = checkserver($pidfile);
+        if($pid) {
+            print STDERR "RUN: got http server pid from pidfile\n" if($verbose);
+            $verified = 1;
+            last;
+        }
+
         if ( $data =~ /WE ROOLZ: (\d+)/ ) {
             $pid = 0+$1;
             $verified = 1;
@@ -1228,6 +1236,7 @@ sub singletest {
         if($@) {
             print "perl: $code\n";
             print "precommand: $@";
+            stopservers();
             exit;
         }
     }
@@ -1400,6 +1409,7 @@ sub singletest {
         my $filename=$hash{'name'};
         if(!$filename) {
             print "ERROR: section verify=>file has no name attribute!\n";
+            stopservers();
             exit;
         }
         my $filemode=$hash{'mode'};
@@ -1953,7 +1963,6 @@ foreach $testnum (@at) {
 #
 close(CMDLOG);
 
-
 # Tests done, stop the servers
 stopservers();