diff --git a/engine/action.go b/engine/action.go index fff13356c..6c57e8aaa 100644 --- a/engine/action.go +++ b/engine/action.go @@ -426,9 +426,13 @@ func callUrl(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error if sq != nil { o = sq } + jsn, err := json.Marshal(o) + if err != nil { + return err + } cfg := config.CgrConfig() fallbackPath := path.Join(cfg.HttpFailedDir, fmt.Sprintf("act_%s_%s_%s.json", a.ActionType, a.ExtraParameters, utils.GenUUID())) - _, err := utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, o, utils.CONTENT_JSON, 1, fallbackPath) + _, err = utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, jsn, utils.CONTENT_JSON, 1, fallbackPath) return err } @@ -441,9 +445,13 @@ func callUrlAsync(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) if sq != nil { o = sq } + jsn, err := json.Marshal(o) + if err != nil { + return err + } cfg := config.CgrConfig() fallbackPath := path.Join(cfg.HttpFailedDir, fmt.Sprintf("act_%s_%s_%s.json", a.ActionType, a.ExtraParameters, utils.GenUUID())) - go utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, o, utils.CONTENT_JSON, 3, fallbackPath) + go utils.HttpPoster(a.ExtraParameters, cfg.HttpSkipTlsVerify, jsn, utils.CONTENT_JSON, 3, fallbackPath) return nil } diff --git a/engine/cdrs.go b/engine/cdrs.go index 51f1abb24..122bd5fbe 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -19,6 +19,7 @@ along with this program. If not, see package engine import ( + "encoding/json" "fmt" "io/ioutil" "net/http" @@ -443,7 +444,11 @@ func (self *CdrServer) replicateCdr(cdr *CDR) error { body = cdr.AsHttpForm() case utils.META_HTTP_JSON: content = utils.CONTENT_JSON - body = cdr + jsn, err := json.Marshal(cdr) + if err != nil { + return err + } + body = jsn } errChan := make(chan error) go func(body interface{}, rplCfg *config.CdrReplicationCfg, content string, errChan chan error) { diff --git a/sessionmanager/data_it_test.go b/sessionmanager/data_it_test.go index 513941df0..b281c2985 100644 --- a/sessionmanager/data_it_test.go +++ b/sessionmanager/data_it_test.go @@ -258,7 +258,7 @@ func TestSMGDataLastUsedMultipleData(t *testing.T) { if maxUsage != 1.048576e+06 { t.Error("Bad max usage: ", maxUsage) } - eAcntVal = 49997849600.000000 // 20480 + eAcntVal = 49998883840.000000 // 20480 if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.DATA].GetTotalValue() != eAcntVal { @@ -285,7 +285,7 @@ func TestSMGDataLastUsedMultipleData(t *testing.T) { if maxUsage != 1.048576e+06 { t.Error("Bad max usage: ", maxUsage) } - eAcntVal = 49997829120.000000 // 20480 + eAcntVal = 49998863360.000000 // 20480 if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.DATA].GetTotalValue() != eAcntVal { @@ -311,7 +311,7 @@ func TestSMGDataLastUsedMultipleData(t *testing.T) { if maxUsage != 1.048576e+06 { t.Error("Bad max usage: ", maxUsage) } - eAcntVal = 49996774400.000000 // 1054720 + eAcntVal = 49998842880.000000 // 20480 if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.DATA].GetTotalValue() != eAcntVal { diff --git a/sessionmanager/smg_it_test.go b/sessionmanager/smg_it_test.go index e553ba148..ba131c5e0 100644 --- a/sessionmanager/smg_it_test.go +++ b/sessionmanager/smg_it_test.go @@ -392,7 +392,7 @@ func TestSMGLastUsed(t *testing.T) { if maxUsage != 120 { t.Error("Bad max usage: ", maxUsage) } - eAcntVal = 6.490110 + eAcntVal = 6.590100 if err := smgRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { diff --git a/sessionmanager/smg_session.go b/sessionmanager/smg_session.go index fa623536b..435842c86 100644 --- a/sessionmanager/smg_session.go +++ b/sessionmanager/smg_session.go @@ -80,10 +80,9 @@ func (self *SMGSession) debitLoop(debitInterval time.Duration) { func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.Duration, error) { requestedDuration := dur self.totalUsage += lastUsed // Should reflect the total usage so far - //utils.Logger.Debug(fmt.Sprintf("ExtraDuration: %d", self.extraDuration)) if lastUsed > 0 { self.extraDuration = self.lastUsage - lastUsed - //utils.Logger.Debug(fmt.Sprintf("ExtraDuration LastUsed: %d", self.extraDuration)) + //utils.Logger.Debug(fmt.Sprintf("ExtraDuration LastUsed: %f", self.extraDuration.Seconds())) } // apply correction from previous run if self.extraDuration < dur { @@ -93,7 +92,8 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.D self.extraDuration -= dur return ccDuration, nil } - + //utils.Logger.Debug(fmt.Sprintf("dur: %f", dur.Seconds())) + initialExtraDuration := self.extraDuration self.extraDuration = 0 if self.cd.LoopIndex > 0 { self.cd.TimeStart = self.cd.TimeEnd @@ -118,12 +118,12 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.D self.cd.LoopIndex += 1 self.sessionCds = append(self.sessionCds, self.cd.Clone()) self.callCosts = append(self.callCosts, cc) - self.lastUsage = ccDuration + self.lastUsage = initialExtraDuration + ccDuration if ccDuration >= dur { // we got what we asked to be debited return requestedDuration, nil } - return ccDuration, nil + return initialExtraDuration + ccDuration, nil } // Attempts to refund a duration, error on failure diff --git a/utils/httpclient.go b/utils/httpclient.go index 5e048ebd0..0fad55afb 100644 --- a/utils/httpclient.go +++ b/utils/httpclient.go @@ -80,7 +80,7 @@ func HttpPoster(addr string, skipTlsVerify bool, content interface{}, contentTyp var err error switch contentType { case CONTENT_JSON: - body, err = json.Marshal(content) + body = content.([]byte) case CONTENT_FORM: urlData = content.(url.Values) case CONTENT_TEXT: diff --git a/utils/httpclient_local_test.go b/utils/httpclient_local_test.go index 7d73b00bd..ecdf49481 100644 --- a/utils/httpclient_local_test.go +++ b/utils/httpclient_local_test.go @@ -39,15 +39,15 @@ func TestHttpJsonPoster(t *testing.T) { return } content := &TestContent{Var1: "Val1", Var2: "Val2"} + jsn, _ := json.Marshal(content) filePath := "/tmp/cgr_test_http_poster.json" - if _, err := HttpPoster("http://localhost:8080/invalid", true, content, CONTENT_JSON, 3, filePath); err != nil { + if _, err := HttpPoster("http://localhost:8080/invalid", true, jsn, CONTENT_JSON, 3, filePath); err != nil { t.Error(err) } - jsnContent, _ := json.Marshal(content) if readBytes, err := ioutil.ReadFile(filePath); err != nil { t.Error(err) - } else if !reflect.DeepEqual(jsnContent, readBytes) { - t.Errorf("Expecting: %q, received: %q", string(jsnContent), string(readBytes)) + } else if !reflect.DeepEqual(jsn, readBytes) { + t.Errorf("Expecting: %q, received: %q", string(jsn), string(readBytes)) } if err := os.Remove(filePath); err != nil { t.Error("Failed removing file: ", filePath)