]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: improve mqtt server handling
authorStefan Eissing <stefan@eissing.org>
Thu, 26 Sep 2024 13:00:27 +0000 (15:00 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 26 Sep 2024 21:35:13 +0000 (23:35 +0200)
Check that the mqtt server process actually is running.
Handle its port number similar to other servers.

Closes #15059

tests/servers.pm

index 0938aaa93fe5a8c62d0b53a41ceb1c461e5d8b3a..9badf5da1fd19ff5c64e9a19e2bae49dcd94c92b 100644 (file)
@@ -908,6 +908,20 @@ sub verifyhttptls {
     return $pid;
 }
 
+#######################################################################
+# STUB for verifying mqtt
+#
+sub verifymqtt {
+    my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
+    my $pidfile = server_pidfilename("$LOGDIR/$PIDDIR", $proto, $ipvnum,
+                                     $idnum);
+    my $pid = processexists($pidfile);
+    if($pid < 0) {
+        logmsg "RUN: MQTT server has died after starting up\n";
+    }
+    return $pid;
+}
+
 #######################################################################
 # STUB for verifying socks
 #
@@ -1064,6 +1078,7 @@ my %protofunc = ('http' => \&verifyhttp,
                  'ftps' => \&verifyftp,
                  'pop3s' => \&verifyftp,
                  'imaps' => \&verifyftp,
+                 'mqtt' => \&verifymqtt,
                  'smtps' => \&verifyftp,
                  'tftp' => \&verifyftp,
                  'ssh' => \&verifyssh,
@@ -1952,13 +1967,12 @@ sub runmqttserver {
     }
 
     my $mqttport = pidfromfile($portfile);
-    $PORT{"mqtt"} = $mqttport;
 
     if($verb) {
         logmsg "RUN: $srvrname server is now running PID $pid2 on PORT $mqttport\n";
     }
 
-    return (0, $pid2, $sockspid);
+    return (0, $pid2, $sockspid, $mqttport);
 }
 
 #######################################################################
@@ -2240,6 +2254,19 @@ sub responsive_http_server {
     return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port_or_path, $do_http3);
 }
 
+#######################################################################
+# Single shot mqtt server responsiveness test. This should only
+# be used to verify that a server present in %run hash is still functional
+#
+sub responsive_mqtt_server {
+    my ($proto, $id, $verb, $ipv6) = @_;
+    my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
+    my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
+    my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+
+    return &responsiveserver($proto, $ipvnum, $idnum, $ip);
+}
+
 #######################################################################
 # Single shot pingpong server responsiveness test. This should only be
 # used to verify that a server present in %run hash is still functional
@@ -2876,8 +2903,14 @@ sub startservers {
             }
         }
         elsif($what eq "mqtt" ) {
+            if($run{'mqtt'} &&
+               !responsive_mqtt_server("mqtt", "", $verbose)) {
+                if(stopserver('mqtt')) {
+                    return ("failed stopping unresponsive MQTT server", 3);
+                }
+            }
             if(!$run{'mqtt'}) {
-                ($serr, $pid, $pid2) = runmqttserver("", $verbose);
+                ($serr, $pid, $pid2, $PORT{"mqtt"}) = runmqttserver("", $verbose);
                 if($pid <= 0) {
                     return ("failed starting mqtt server", $serr);
                 }