From dd1749e53e26a93ecf1aede61fa9e08193ff0b50 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Wed, 4 Aug 2021 13:35:30 +0200 Subject: [PATCH] TT#135050 properly report rate-o-mat failure reason the perl statement do $pl_file; requires different handling in rate-o-mat launchers in order to propagate the orignating error properly. Change-Id: Ie1496236be62c4f6fc5767492ece8607dc179aa0 --- rate-o-mat.pl | 10 ++++------ t/Utils/Rateomat.pm | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/rate-o-mat.pl b/rate-o-mat.pl index bc629c5..ff85812 100755 --- a/rate-o-mat.pl +++ b/rate-o-mat.pl @@ -2032,8 +2032,7 @@ sub get_unrated_cdrs { my $r_cdrs = shift; my $sth = $sth_unrated_cdrs; - $sth->execute - or FATAL "Error executing unrated cdr statement: ".$sth->errstr; + $sth->execute or die("Error executing unrated cdr statement: ".$sth->errstr); my @cdrs = (); @@ -2061,7 +2060,7 @@ sub get_unrated_cdrs { and ($cdr->{id} % 4) == 2) ); } else { - FATAL "Unknown hostname '$nodename'"; + die("Unknown hostname '$nodename'"); } check_shutdown() and return 0; } @@ -2069,8 +2068,7 @@ sub get_unrated_cdrs { # the while above may have been interrupted because there is no # data left, or because there was an error. To decide what # happened, we have to query $sth->err() - FATAL "Error fetching unrated cdr's: ". $sth->errstr - if $sth->err; + die("Error fetching unrated cdr's: ". $sth->errstr) if $sth->err; $sth->finish; if ($shuffle_batch) { @@ -3604,7 +3602,7 @@ sub main { }; $error = $@; if ($error) { - if ($DBI::err == 2006) { + if ($DBI::err and $DBI::err == 2006) { INFO "DB connection gone, retrying..."; close_db(); $init = 1; diff --git a/t/Utils/Rateomat.pm b/t/Utils/Rateomat.pm index 44f6751..7339a0b 100644 --- a/t/Utils/Rateomat.pm +++ b/t/Utils/Rateomat.pm @@ -101,8 +101,15 @@ sub run_rateomat { kill 'HUP', 0; } if defined $timeout; alarm $timeout if defined $timeout; - die($!) if !defined do $rateomat_pl; + my $res = do $rateomat_pl; alarm 0 if defined $timeout; + if ($@) { + diag("rate-o-mat: " . $@); + return 0; + } elsif (not $res) { + diag("rate-o-mat: " . $!); + return 0; + } return 1; }; alarm 0 if defined $timeout; @@ -126,13 +133,13 @@ sub run_rateomat_threads { diag("timeout for rate-o-mat thread $tid"); threads->exit(); } if defined $timeout; - eval { - die($!) if !defined do $rateomat_pl; - return 1; - }; + my $res = do $rateomat_pl; if ($@) { diag("rate-o-mat thread $tid: " . $@); return 0; + } elsif (not $res) { + diag("rate-o-mat thread $tid: " . $!); + return 0; } return 1; }));