mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge fix
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user