correction for deep hidden bug :)

This commit is contained in:
Radu Ioan Fericean
2012-08-10 22:09:22 +03:00
parent 7110b40238
commit 9b7377e7f8
10 changed files with 49 additions and 17 deletions

View File

@@ -15,4 +15,4 @@ notifications:
on_success: change
on_failure: always
after_script: ./build_and_test.sh
after_script: ./test.sh

12
build.sh Executable file
View File

@@ -0,0 +1,12 @@
#! /usr/bin/env sh
go install github.com/cgrates/cgrates/cmd/cgr-rater
cr=$?
go install github.com/cgrates/cgrates/cmd/cgr-loader
cl=$?
go install github.com/cgrates/cgrates/cmd/cgr-console
cc=$?
exit $cr || $cl || $cc

View File

@@ -26,4 +26,7 @@ enabled = true
rater = internal #address where to access rater. Can be internal, direct rater address or the address of a balancer
freeswitch_server = localhost:8021
freeswitch_pass = ClueCon
rpc_encoding = gob
rpc_encoding = gob
[scheduler]
enabled = true

View File

@@ -1,9 +1,5 @@
#! /usr/bin/env sh
go install github.com/cgrates/cgrates/cmd/cgr-rater
go install github.com/cgrates/cgrates/cmd/cgr-loader
go install github.com/cgrates/cgrates/cmd/cgr-console
go test github.com/cgrates/cgrates/timespans
ts=$?
go test github.com/cgrates/cgrates/sessionmanager

View File

@@ -80,7 +80,11 @@ func (ap *ActivationPeriod) restore(input string) {
elements := strings.Split(input, "|")
unixNano, _ := strconv.ParseInt(elements[0], 10, 64)
ap.ActivationTime = time.Unix(0, unixNano).In(time.UTC)
for _, is := range elements[1 : len(elements)-1] {
els := elements[1:]
if len(els) > 1 {
els = elements[1 : len(elements)-1]
}
for _, is := range els {
i := &Interval{}
i.restore(is)
ap.Intervals = append(ap.Intervals, i)

View File

@@ -48,6 +48,15 @@ func TestApStoreRestore(t *testing.T) {
}
}
func TestApRestoreFromString(t *testing.T) {
s := "1325376000000000000|;1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5,6,0;00:00:00;;10;0;0.2;60;1\n"
ap := ActivationPeriod{}
ap.restore(s)
if len(ap.Intervals) != 1 {
t.Error("Error restoring activation period from string", ap)
}
}
func TestApRestoreFromStorage(t *testing.T) {
cd := &CallDescriptor{
Direction: "OUT",

View File

@@ -153,9 +153,6 @@ func (cd *CallDescriptor) SearchStorageForPrefix() (destPrefix string, err error
}
//load the activation preriods
if err == nil && len(values) > 0 {
if len(values[0].Intervals) > 0 {
Logger.Debug(fmt.Sprintf("Activation periods: ", values[0].Intervals))
}
cd.ActivationPeriods = values
}
return

View File

@@ -48,6 +48,15 @@ func TestIntervalStoreRestore(t *testing.T) {
}
}
func TestIntervalRestoreFromString(t *testing.T) {
s := ";1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5,6,0;00:00:00;;10;0;0.2;60;1"
i := Interval{}
i.restore(s)
if i.Price != 0.2 {
t.Errorf("Error restoring inteval period from string %+v", i)
}
}
func TestIntervalMonth(t *testing.T) {
i := &Interval{Months: Months{time.February}}
d := time.Date(2012, time.February, 10, 23, 0, 0, 0, time.UTC)

View File

@@ -102,9 +102,11 @@ De-serializes the minute bucket for the storage. Used for key-value storages.
*/
func (mb *MinuteBucket) restore(input string) {
elements := strings.Split(input, ";")
mb.Seconds, _ = strconv.ParseFloat(elements[0], 64)
mb.Weight, _ = strconv.ParseFloat(elements[1], 64)
mb.Price, _ = strconv.ParseFloat(elements[2], 64)
mb.Percent, _ = strconv.ParseFloat(elements[3], 64)
mb.DestinationId = elements[4]
if len(elements) == 5 {
mb.Seconds, _ = strconv.ParseFloat(elements[0], 64)
mb.Weight, _ = strconv.ParseFloat(elements[1], 64)
mb.Price, _ = strconv.ParseFloat(elements[2], 64)
mb.Percent, _ = strconv.ParseFloat(elements[3], 64)
mb.DestinationId = elements[4]
}
}

View File

@@ -122,7 +122,7 @@ If the amount is bigger than the sum of all seconds in the minute buckets than n
debited and an error will be returned.
*/
func (ub *UserBalance) debitMinutesBalance(amount float64, prefix string, count bool) error {
if count && amount > 0 {
if count {
ub.countUnits(&Action{BalanceId: MINUTES, Direction: OUTBOUND, MinuteBucket: &MinuteBucket{Seconds: amount, DestinationId: prefix}})
}
avaliableNbSeconds, _, bucketList := ub.getSecondsForPrefix(prefix)
@@ -169,7 +169,7 @@ func (ub *UserBalance) debitMinutesBalance(amount float64, prefix string, count
Debits some amount of user's specified balance. Returns the remaining credit in user's balance.
*/
func (ub *UserBalance) debitBalance(balanceId string, amount float64, count bool) float64 {
if count && amount > 0 {
if count {
ub.countUnits(&Action{BalanceId: balanceId, Direction: OUTBOUND, Units: amount})
}
ub.BalanceMap[balanceId+OUTBOUND] -= amount