TT#39612 fix balance lookup for 23:59:59.xxx start/end time

Change-Id: I0985a28c1617439016c8b039806ddb0ad2854b25
changes/17/22317/7
Rene Krenn 7 years ago
parent 1e2143041a
commit 9bef1b25cd

@ -52,7 +52,7 @@ my $update_prepaid_preference = 1;
my $use_customer_real_cost = 0;
my $use_provider_real_cost = 0;
# don't update balance of prepaid contracts, if no prepaid_costs record is found (re-rating):
my $prepaid_update_balance = 0;
my $prepaid_update_balance = ((defined $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} && $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE}) ? int $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} : 0);
# control writing cdr relation data:
# disable it for now until this will be limited to prepaid contracts,
@ -139,7 +139,7 @@ my $cps_info = {
t => 0.0,
t_old => 0.0,
dt => 0.0,
dt => 0.0,
delay => 0.0,
cps => 0.0,
@ -1471,10 +1471,10 @@ sub get_contract_balances {
my $start_time = $cdr->{start_time};
my $duration = $cdr->{duration};
catchup_contract_balance($start_time,$start_time + $duration,$contract_id,$r_package_info);
catchup_contract_balance(int($start_time),int($start_time + $duration),$contract_id,$r_package_info);
my $sth = $sth_get_cbalances;
$sth->execute($contract_id, $start_time)
$sth->execute($contract_id, int($start_time))
or FATAL "Error executing get contract balance statement: ".$sth->errstr;
my $res = $sth->fetchall_arrayref({});
$sth->finish;
@ -2958,7 +2958,7 @@ sub main {
}
INFO "Up and running.\n";
while (!$shutdown) {
$log_fatal = 1;
@ -3090,6 +3090,9 @@ _update_cps(1); # unless ($rated_batch % 5);
_update_cps(0);
_cps_delay();
}
if ($debug && $split_peak_parts && (scalar @cdrs) < 5) {
sleep $loop_interval; #split peak parts testcase
}
$shutdown and last;

@ -13,9 +13,9 @@ our @EXPORT_OK = qw(
);
## no critic (Variables::RequireLocalizedPunctuationVars)
#$ENV{RATEOMAT_BILLING_DB_HOST} = '192.168.0.84';
#$ENV{RATEOMAT_PROVISIONING_DB_HOST} = '192.168.0.84';
#$ENV{RATEOMAT_ACCOUNTING_DB_HOST} = '192.168.0.84';
#$ENV{RATEOMAT_BILLING_DB_HOST} = '192.168.0.29';
#$ENV{RATEOMAT_PROVISIONING_DB_HOST} = '192.168.0.29';
#$ENV{RATEOMAT_ACCOUNTING_DB_HOST} = '192.168.0.29';
$ENV{CATALYST_SERVER} = 'https://127.0.0.1:1443';

@ -18,6 +18,7 @@ use Test::More;
### and cash balance interval values.
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
local $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} = 1;
my $init_secs = 60;
my $follow_secs = 30;

@ -19,6 +19,7 @@ use Test::More;
### balance.
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
local $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} = 1;
use Text::Table;
use Text::Wrap;

@ -18,6 +18,7 @@ use Test::More;
### for both prepaid and postpaid (new).
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
local $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} = 1;
Utils::Env::set_local_timezone('UTC','+00:00'); #'UTC'; #vagrant SYSTEM timezone is "Etc/UTC"
my $init_secs = 50;

@ -21,6 +21,7 @@ use Storable qw();
### note: this tests takes longer time to complete
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
local $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} = 1;
Utils::Api::set_time(Utils::Api::get_now->subtract(months => 5));
#provider contract needs to be created in the past as well:

@ -0,0 +1,111 @@
use strict;
use warnings;
use File::Basename;
use Cwd;
use lib Cwd::abs_path(File::Basename::dirname(__FILE__));
use DateTime qw();
use Utils::Api qw();
use Utils::Rateomat qw();
use Test::More;
### testcase outline:
### test calls starting/ending at 23:59:59.xxx
my $provider = create_provider();
{
my $callee = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[0]->{profile},undef,{ cc => 888, ac => '2<n>', sn => '<t>' });
my $caller = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[0]->{profile},undef,{ cc => 888, ac => '1<n>', sn => '<t>' });
my $costs_initial = $provider->{subscriber_fees}->[0]->{fee}->{onpeak_init_rate} *
$provider->{subscriber_fees}->[0]->{fee}->{onpeak_init_interval};
my $now = Utils::Api::get_now();
my $start = $now->clone->add(months => 1)->truncate(to => 'month')->subtract(seconds => 2)->epoch + 0.567;
my $duration = 1.0;
my @cdr_ids = map { $_->{id}; } @{ Utils::Rateomat::create_cdrs([
Utils::Rateomat::prepare_cdr($caller->{subscriber},undef,$caller->{reseller},
$callee->{subscriber},undef,$callee->{reseller},
'192.168.0.1',$start,$duration),
]) };
if (ok((scalar @cdr_ids) > 0 && Utils::Rateomat::run_rateomat_threads(),'rate-o-mat executed')) {
ok(Utils::Rateomat::check_cdrs('',
map { $_ => {
id => $_,
rating_status => 'ok',
source_customer_cost => Utils::Rateomat::decimal_to_string($costs_initial) };
} @cdr_ids
),'cdrs were all processed');
my $label = 'cdr with end time at '.Utils::Api::datetime_to_string(DateTime->from_epoch(epoch => ($start + $duration))).': ';
Utils::Api::check_interval_history($label,$caller->{customer}->{id},[
{ start => Utils::Api::datetime_to_string($now->clone->truncate(to => 'month')),
stop => Utils::Api::datetime_to_string($now->clone->add(months => 1)->truncate(to => 'month')->subtract(seconds => 1)),
},
]);
}
}
{
my $amount = 5;
my $callee = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[0]->{profile},undef,{ cc => 888, ac => '2<n>', sn => '<t>' });
my $caller = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[0]->{profile},$amount,{ cc => 888, ac => '1<n>', sn => '<t>' });
my $costs_initial = ($provider->{subscriber_fees}->[0]->{fee}->{onpeak_init_rate} *
$provider->{subscriber_fees}->[0]->{fee}->{onpeak_init_interval}) / 100.0;
my $now = Utils::Api::get_now();
my $start = $now->clone->add(months => 1)->truncate(to => 'month')->subtract(seconds => 1)->epoch + 0.567;
my @cdr_ids = map { $_->{id}; } @{ Utils::Rateomat::create_cdrs([
Utils::Rateomat::prepare_cdr($caller->{subscriber},undef,$caller->{reseller},
$callee->{subscriber},undef,$callee->{reseller},
'192.168.0.1',$start,1),
]) };
if (ok((scalar @cdr_ids) > 0 && Utils::Rateomat::run_rateomat_threads(),'rate-o-mat executed')) {
ok(Utils::Rateomat::check_cdrs('',
map { $_ => {
id => $_,
rating_status => 'ok', };
} @cdr_ids
),'cdrs were all processed');
my $label = 'cdr with start time at '.Utils::Api::datetime_to_string(DateTime->from_epoch(epoch => $start)).': ';
Utils::Api::check_interval_history($label,$caller->{customer}->{id},[
{ start => Utils::Api::datetime_to_string($now->clone->truncate(to => 'month')),
stop => Utils::Api::datetime_to_string($now->clone->add(months => 1)->truncate(to => 'month')->subtract(seconds => 1)),
cash => $amount - $costs_initial,
},
{ start => Utils::Api::datetime_to_string($now->clone->add(months => 1)->truncate(to => 'month')),
stop => Utils::Api::datetime_to_string($now->clone->add(months => 2)->truncate(to => 'month')->subtract(seconds => 1)),
cash => $amount - $costs_initial,
},
]);
}
}
done_testing();
exit;
sub create_provider {
return Utils::Api::setup_provider('test<n>.com',
[ #rates:
{ #initial:
onpeak_init_rate => 2,
onpeak_init_interval => 60,
onpeak_follow_rate => 1,
onpeak_follow_interval => 30,
offpeak_init_rate => 2,
offpeak_init_interval => 60,
offpeak_follow_rate => 1,
offpeak_follow_interval => 30,
},
],
[ #billing networks:
]
);
}

@ -22,6 +22,7 @@ use List::Util qw();
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
local $ENV{RATEOMAT_SPLIT_PEAK_PARTS} = 1;
local $ENV{RATEOMAT_PREPAID_UPDATE_BALANCE} = 1;
local $ENV{RATEOMAT_BATCH_SIZE} = 1;
#use Text::Table;

Loading…
Cancel
Save