create incerements for getcost as well

This commit is contained in:
Radu Ioan Fericean
2015-11-30 19:37:43 +02:00
parent b779c4685c
commit f57ebb16d2
5 changed files with 11 additions and 4 deletions

View File

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

View File

@@ -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("<Rater> Going negative on account %s with AllowNegative: false", cd.GetAccountKey()))
}
leftCC.Timespans.Decompress()
for _, ts := range leftCC.Timespans {
if ts.Increments == nil {
ts.createIncrementsSlice()

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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)