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; }