From 841fbdb63ccfce6e32fc9dc9882a3822a8aa17e8 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 26 Sep 2024 15:00:27 +0200 Subject: [PATCH] tests: improve mqtt server handling Check that the mqtt server process actually is running. Handle its port number similar to other servers. Closes #15059 --- tests/servers.pm | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/servers.pm b/tests/servers.pm index 0938aaa93f..9badf5da1f 100644 --- a/tests/servers.pm +++ b/tests/servers.pm @@ -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); } -- 2.47.3