From 9d82d0876ad4e89e1dc1e691c7ddc5959909a30a Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 7 May 2025 08:49:56 -0400 Subject: [PATCH] MT#55283 refactor autotest_init Don't depend on ->socket being set. Instead run the actual ping check and use that as condition to see whether the daemon is ready or not. Change-Id: I6d39ca6cb9b3a61a94194fe827768dff28ca0508 --- perl/NGCP/Rtpengine/AutoTest.pm | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/perl/NGCP/Rtpengine/AutoTest.pm b/perl/NGCP/Rtpengine/AutoTest.pm index ff9213bc8..c6d9a7e6e 100644 --- a/perl/NGCP/Rtpengine/AutoTest.pm +++ b/perl/NGCP/Rtpengine/AutoTest.pm @@ -59,6 +59,10 @@ sub autotest_start { ok $rtpe_pid, 'daemon launched in background'; } + if ($launch_cb) { + $launch_cb->(); + } + return autotest_init(); } @@ -66,28 +70,27 @@ sub autotest_init { # keep trying to connect to the control socket while daemon is starting up for (1 .. 300) { $c = NGCP::Rtpengine->new($ENV{RTPENGINE_HOST} // '127.0.0.1', $ENV{RTPENGINE_PORT} // 2223); - last if $c->{socket}; Time::HiRes::usleep(100000); # 100 ms x 300 = 30 sec - } - 1; - $c->{socket} or die; + $tag_iter = 0; + $tag_suffix = '-' . rand(); - $tag_iter = 0; - $tag_suffix = '-' . rand(); + my $ok = 0; + eval { + my $r = $c->req({command => 'ping'}); + $ok = $r->{result} eq 'pong'; + }; - if ($launch_cb) { - $launch_cb->(); - } + next if not $ok; - my $r = $c->req({command => 'ping'}); - ok $r->{result} eq 'pong', 'ping works, daemon operational'; + # Setup a global die handler. + ## no critic (Variables::RequireLocalizedPunctuationVars) + $SIG{__DIE__} = sub { + terminate(@_); + }; - # Setup a global die handler. - ## no critic (Variables::RequireLocalizedPunctuationVars) - $SIG{__DIE__} = sub { - terminate(@_); - }; + last; + } return 1; }