Browse Source

MT#55283 add test callback functions

Make it possible to run custom code between sending out a command and
expecting and receiving the answer.

Change-Id: I11359b144a27c58de8ec2b136bd6715c7d1b9cce
pull/1611/head
Richard Fuchs 3 years ago
parent
commit
088a2db0d7
2 changed files with 12 additions and 0 deletions
  1. +7
    -0
      perl/NGCP/Rtpengine.pm
  2. +5
    -0
      perl/NGCP/Rtpengine/AutoTest.pm

+ 7
- 0
perl/NGCP/Rtpengine.pm View File

@ -10,6 +10,10 @@ use Bencode;
use Data::Dumper;
use JSON;
our $req_cb;
sub new {
my ($class, $addr, $port) = @_;
@ -33,6 +37,9 @@ sub req {
my $cookie = rand() . ' ';
my $p = $cookie . ($self->{json} ? encode_json($packet) : Bencode::bencode($packet));
$self->{socket}->send($p, 0) or die $!;
if ($req_cb) {
$req_cb->();
}
my $ret;
$self->{socket}->recv($ret, 65535) or die $!;
$ret =~ s/^\Q$cookie\E//s or die $ret;


+ 5
- 0
perl/NGCP/Rtpengine/AutoTest.pm View File

@ -15,6 +15,7 @@ use Exporter;
our @ISA;
our @EXPORT;
our $launch_cb;
BEGIN {
require Exporter;
@ -75,6 +76,10 @@ sub autotest_init {
$tag_iter = 0;
$tag_suffix = '-' . rand();
if ($launch_cb) {
$launch_cb->();
}
my $r = $c->req({command => 'ping'});
ok $r->{result} eq 'pong', 'ping works, daemon operational';


Loading…
Cancel
Save