From f57ebb16d2da42bb6e6257d9aca6789079ad4f70 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 30 Nov 2015 19:37:43 +0200 Subject: [PATCH] create incerements for getcost as well --- console/actions.go | 6 ++++-- engine/account.go | 3 ++- engine/account_test.go | 3 +++ engine/calldesc.go | 1 + engine/calldesc_test.go | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/console/actions.go b/console/actions.go index 3365a87b6..25e9af0e5 100644 --- a/console/actions.go +++ b/console/actions.go @@ -24,7 +24,6 @@ func init() { c := &CmdGetActions{ name: "actions", rpcMethod: "ApierV2.GetActions", - rpcParams: "", } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -34,7 +33,7 @@ func init() { type CmdGetActions struct { name string rpcMethod string - rpcParams string + rpcParams *StringWrapper *CommandExecuter } @@ -47,6 +46,9 @@ func (self *CmdGetActions) RpcMethod() string { } func (self *CmdGetActions) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &StringWrapper{} + } return self.rpcParams } diff --git a/engine/account.go b/engine/account.go index 555545efc..dc7c5c5c4 100644 --- a/engine/account.go +++ b/engine/account.go @@ -365,7 +365,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo cc.Timespans = append(cc.Timespans, leftCC.Timespans...) } - //log.Printf("HERE: %+v %d", leftCC) + //log.Printf("HERE: %+v", leftCC) if leftCC.Cost > 0 && goNegative { initialLength := len(cc.Timespans) cc.Timespans = append(cc.Timespans, leftCC.Timespans...) @@ -379,6 +379,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo if len(leftCC.Timespans) > 0 && leftCC.Cost > 0 && !ub.AllowNegative && !dryRun { utils.Logger.Err(fmt.Sprintf(" Going negative on account %s with AllowNegative: false", cd.GetAccountKey())) } + leftCC.Timespans.Decompress() for _, ts := range leftCC.Timespans { if ts.Increments == nil { ts.createIncrementsSlice() diff --git a/engine/account_test.go b/engine/account_test.go index a272d0251..0cdcc7c10 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -143,6 +143,9 @@ func TestGetSpecialPricedSeconds(t *testing.T) { expected := 20 * time.Second if credit != 0 || seconds != expected || len(bucketList) != 2 || bucketList[0].Weight < bucketList[1].Weight { t.Log(seconds, credit, bucketList) + for _, b := range bucketList { + t.Logf("Balance: %+v", b) + } t.Errorf("Expected %v was %v", expected, seconds) } } diff --git a/engine/calldesc.go b/engine/calldesc.go index b98e3def8..96dacd589 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -503,6 +503,7 @@ func (cd *CallDescriptor) getCost() (*CallCost, error) { cost := 0.0 for i, ts := range timespans { + ts.createIncrementsSlice() // only add connect fee if this is the first/only call cost request //log.Printf("Interval: %+v", ts.RateInterval.Timing) if cd.LoopIndex == 0 && i == 0 && ts.RateInterval != nil { diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 75926480f..2e8744fcd 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -574,7 +574,7 @@ func TestGetCostRoundingIssue(t *testing.T) { MaxCostSoFar: 0, } cc, err := cd.GetCost() - expected := 0.17 + expected := 0.39 if cc.Cost != expected || err != nil { t.Log(utils.ToIJSON(cc)) t.Errorf("Expected %v was %+v", expected, cc)