improved refund testing and prepared stres test for profiling

This commit is contained in:
Radu Ioan Fericean
2013-12-13 22:43:46 +02:00
parent fac3fa5025
commit 8a36ac72b9
2 changed files with 29 additions and 10 deletions

View File

@@ -20,29 +20,47 @@ package main
import (
"flag"
"github.com/cgrates/cgrates/engine"
"log"
"net/rpc"
"os"
"github.com/cgrates/cgrates/engine"
//"net/rpc/jsonrpc"
"net/rpc/jsonrpc"
"runtime"
"runtime/pprof"
"time"
)
var (
balancer = flag.String("balancer", "localhost:2012", "balancer server address")
runs = flag.Int("runs", 10000, "stress cycle number")
parallel = flag.Int("parallel", 0, "run n requests in parallel")
json = flag.Bool("json", false, "use JSON for RPC encoding")
balancer = flag.String("balancer", "localhost:2012", "balancer server address")
runs = flag.Int("runs", 10000, "stress cycle number")
parallel = flag.Int("parallel", 0, "run n requests in parallel")
json = flag.Bool("json", false, "use JSON for RPC encoding")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
runtime.GOMAXPROCS(runtime.NumCPU())
t1 := time.Date(2013, time.August, 07, 17, 30, 0, 0, time.UTC)
t2 := time.Date(2013, time.August, 07, 18, 30, 0, 0, time.UTC)
cd := engine.CallDescriptor{Direction: "*out", TOR: "call", Tenant: "cgrates.org", Subject: "1001", Destination: "+49", TimeStart: t1, TimeEnd: t2}
cd := engine.CallDescriptor{
TimeStart: time.Date(2013, time.December, 13, 22, 30, 0, 0, time.UTC),
TimeEnd: time.Date(2013, time.December, 13, 22, 31, 0, 0, time.UTC),
CallDuration: 60 * time.Second,
Direction: "*out",
TOR: "call",
Tenant: "cgrates.org",
Subject: "1001",
Destination: "+49",
}
result := engine.CallCost{}
var client *rpc.Client
var err error

View File

@@ -1015,7 +1015,7 @@ func TestUserBalanceUnitCountingOutboundInbound(t *testing.T) {
}
}
func TestUserBalanceRefundSimple(t *testing.T) {
func TestUserBalanceRefund(t *testing.T) {
ub := &UserBalance{
BalanceMap: map[string]BalanceChain{
CREDIT + OUTBOUND: BalanceChain{
@@ -1028,12 +1028,13 @@ func TestUserBalanceRefundSimple(t *testing.T) {
},
}
increments := Increments{
&Increment{Cost: 2, BalanceUuids: []string{"", "moneya"}},
&Increment{Cost: 2, Duration: 3 * time.Second, BalanceUuids: []string{"minutea", "moneya"}},
&Increment{Duration: 4 * time.Second, BalanceUuids: []string{"minuteb", ""}},
}
ub.refundIncrements(increments, OUTBOUND, false)
if ub.BalanceMap[CREDIT+OUTBOUND][0].Value != 102 ||
if ub.BalanceMap[CREDIT+OUTBOUND][0].Value != 104 ||
ub.BalanceMap[MINUTES+OUTBOUND][0].Value != 13 ||
ub.BalanceMap[MINUTES+OUTBOUND][1].Value != 14 {
t.Error("Error refounding money: ", ub.BalanceMap[MINUTES+OUTBOUND][1].Value)