From 8442dba2bf354428fc201ee743811964f0617c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:40:37 -0300 Subject: [PATCH] test(genesis): cover destiny client termination --- xCAT-test/unit/genesis_openembedded_runtime.t | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/xCAT-test/unit/genesis_openembedded_runtime.t b/xCAT-test/unit/genesis_openembedded_runtime.t index 81eab2e04..24231e5eb 100644 --- a/xCAT-test/unit/genesis_openembedded_runtime.t +++ b/xCAT-test/unit/genesis_openembedded_runtime.t @@ -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, "\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"