2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-08-27 17:16:40 +00:00

test(genesis): cover destiny client termination

This commit is contained in:
Vinícius Ferrão
2026-08-20 22:40:37 -03:00
parent 6c534cb888
commit 8442dba2bf
@@ -7,6 +7,7 @@ use File::Spec;
use File::Temp qw(tempdir);
use FindBin;
use IO::Socket::INET;
use POSIX qw(WNOHANG);
use Test::More;
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
@@ -74,6 +75,30 @@ sub capture_command {
return ( $? >> 8, $output );
}
sub terminate_command {
my ( $environment, @command ) = @_;
my $pid = fork();
die "Unable to fork signal test: $!" unless defined($pid);
if ( $pid == 0 ) {
local %ENV = ( %ENV, %{$environment} );
open( STDOUT, '>', File::Spec->devnull() ) or exit 125;
open( STDERR, '>', File::Spec->devnull() ) or exit 125;
exec @command;
exit 125;
}
select( undef, undef, undef, 0.2 );
kill 'TERM', $pid;
for ( 1 .. 30 ) {
my $result = waitpid( $pid, WNOHANG );
return $? >> 8 if $result == $pid;
select( undef, undef, undef, 0.1 );
}
kill 'KILL', $pid;
waitpid( $pid, 0 );
return undef;
}
my $root = tempdir( CLEANUP => 1 );
my $bin = File::Spec->catdir( $root, 'bin' );
my $state_dir = File::Spec->catdir( $root, 'run' );
@@ -176,6 +201,8 @@ write_file(
<<'SH', 0755
#!/bin/sh
printf 'openssl %s\n' "$*" >>"$XCAT_TEST_LOG"
[ -z "${XCAT_TEST_OPENSSL_DELAY-}" ] \
|| exec sleep "$XCAT_TEST_OPENSSL_DELAY"
cat "$XCAT_TEST_RESPONSE_FILE"
SH
);
@@ -297,6 +324,37 @@ write_file( $destiny_response, "<xcatresponse/>\n" );
);
isnt( $destiny_status, 0, 'nextdestiny rejects an incomplete response' );
( $destiny_status, $destiny_output ) = capture_command(
\%environment,
'/bin/bash', $nextdestiny_script, '192.0.2.10:3001'
);
is( $destiny_status, 0, 'legacy nextdestiny returns an incomplete response' );
is( $destiny_output, "error=No destiny command received\n",
'legacy nextdestiny leaves retry pacing to doxcat' );
{
my %signal_environment = (
%environment,
XCAT_TEST_OPENSSL_DELAY => 30,
);
is(
terminate_command(
\%signal_environment,
'/bin/bash', $getdestiny_script, '192.0.2.10:3001'
),
143,
'SIGTERM stops getdestiny during a request'
);
is(
terminate_command(
\%signal_environment,
'/bin/bash', $nextdestiny_script, '192.0.2.10:3001'
),
143,
'SIGTERM stops nextdestiny during a request'
);
}
write_file(
$cmdline,
"xcatd=127.0.0.1:$listener_port BOOTIF=01-52-54-00-00-00-35\n"