INtegrated CPUProfile in other tests

This commit is contained in:
porosnicuadrian
2021-06-25 16:44:48 +03:00
committed by Dan Christian Bogos
parent 3eda03fdd2
commit d3968b50c0
6 changed files with 160 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ package v1
import (
"net/rpc"
"os"
"path"
"reflect"
"testing"
@@ -48,6 +49,7 @@ var (
testDispatcherSResetStorDb,
testDispatcherSStartEngine,
testDispatcherSRPCConn,
testDispatcherStartCPUProfiling,
testDispatcherSSetDispatcherProfile,
testDispatcherSGetDispatcherProfileIDs,
@@ -65,6 +67,7 @@ var (
testDispatcherSSetDispatcherHostWithoutTenant,
testDispatcherSRemDispatcherHostWithoutTenant,
testV1DispatcherStopCPUProfiling,
testDispatcherSKillEngine,
//cache test
@@ -143,6 +146,15 @@ func testDispatcherSRPCConn(t *testing.T) {
}
}
func testDispatcherStartCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := dispatcherRPC.Call(utils.CoreSv1StartCPUProfiling,
argPath, &reply); err != nil {
t.Error(err)
}
}
func testDispatcherSSetDispatcherProfile(t *testing.T) {
var reply string
dispatcherProfile = &DispatcherWithAPIOpts{
@@ -385,6 +397,32 @@ func testDispatcherSRemDispatcherHost(t *testing.T) {
}
}
func testV1DispatcherStopCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := dispatcherRPC.Call(utils.CoreSv1StopCPUProfiling,
utils.EmptyString, &reply); err != nil {
t.Error(err)
}
file, err := os.Open(argPath)
if err != nil {
t.Error(err)
}
defer file.Close()
//compare the size
size, err := file.Stat()
if err != nil {
t.Error(err)
} else if size.Size() < int64(415) {
t.Errorf("Size of CPUProfile %v is lower that expected", size.Size())
}
//after we checked that CPUProfile was made successfully, can delete it
if err := os.Remove(argPath); err != nil {
t.Error(err)
}
}
func testDispatcherSKillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)

View File

@@ -22,6 +22,7 @@ package v1
import (
"net/rpc"
"os"
"path"
"reflect"
"testing"
@@ -44,6 +45,7 @@ var (
testFilterResetDataDB,
testFilterStartEngine,
testFilterRpcConn,
testFilterStartCPUProfiling,
testFilterGetFilterBeforeSet,
testFilterSetFilter,
testFilterGetFilterAfterSet,
@@ -54,6 +56,7 @@ var (
testFilterGetFilterAfterRemove,
testFilterSetFilterWithoutTenant,
testFilterRemoveFilterWithoutTenant,
testFilterStopCPUProfiling,
testFilterKillEngine,
}
)
@@ -109,6 +112,15 @@ func testFilterRpcConn(t *testing.T) {
}
}
func testFilterStartCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := filterRPC.Call(utils.CoreSv1StartCPUProfiling,
argPath, &reply); err != nil {
t.Error(err)
}
}
func testFilterGetFilterBeforeSet(t *testing.T) {
var reply *engine.Filter
if err := filterRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil ||
@@ -274,3 +286,29 @@ func testFilterRemoveFilterWithoutTenant(t *testing.T) {
t.Error(err)
}
}
func testFilterStopCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := filterRPC.Call(utils.CoreSv1StopCPUProfiling,
utils.EmptyString, &reply); err != nil {
t.Error(err)
}
file, err := os.Open(argPath)
if err != nil {
t.Error(err)
}
defer file.Close()
//compare the size
size, err := file.Stat()
if err != nil {
t.Error(err)
} else if size.Size() < int64(415) {
t.Errorf("Size of CPUProfile %v is lower that expected", size.Size())
}
//after we checked that CPUProfile was made successfully, can delete it
if err := os.Remove(argPath); err != nil {
t.Error(err)
}
}

View File

@@ -251,7 +251,7 @@ func testInternalRemoteITGetAttribute(t *testing.T) {
utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil {
t.Fatal(err)
}
if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
if *encoding == utils.MetaGOB { // in gob empty slice is encoded as nil
alsPrf.AttributeProfile.Attributes[0].FilterIDs = nil
}
reply.Compile()

View File

@@ -21,6 +21,7 @@ package v1
import (
"net/rpc"
"os"
"path"
"reflect"
"sort"
@@ -45,6 +46,7 @@ var (
testV1RsResetStorDb,
testV1RsStartEngine,
testV1RsRpcConn,
testV1ResourceStartCPUProfiling,
testV1RsCacheResourceBeforeLoad,
testV1RsFromFolder,
testV1RsCacheResourceAfterLoad,
@@ -53,6 +55,7 @@ var (
testV1RsAllocateResource,
testV1RsAuthorizeResources,
testV1RsReleaseResource,
testV1ResourceStopCPUProfiling,
testV1RsDBStore,
testV1RsGetResourceProfileBeforeSet,
testV1RsSetResourceProfile,
@@ -155,6 +158,15 @@ func testV1RsRpcConn(t *testing.T) {
}
}
func testV1ResourceStartCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := rlsV1Rpc.Call(utils.CoreSv1StartCPUProfiling,
argPath, &reply); err != nil {
t.Error(err)
}
}
func testV1RsCacheResourceBeforeLoad(t *testing.T) { // cache it with not found
var rplyRes *engine.Resource
if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
@@ -1091,6 +1103,32 @@ func testV1RsCheckAuthorizeResourcesAfterRestart(t *testing.T) {
}
func testV1ResourceStopCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := rlsV1Rpc.Call(utils.CoreSv1StopCPUProfiling,
utils.EmptyString, &reply); err != nil {
t.Error(err)
}
file, err := os.Open(argPath)
if err != nil {
t.Error(err)
}
defer file.Close()
//compare the size
size, err := file.Stat()
if err != nil {
t.Error(err)
} else if size.Size() < int64(415) {
t.Errorf("Size of CPUProfile %v is lower that expected", size.Size())
}
//after we checked that CPUProfile was made successfully, can delete it
if err := os.Remove(argPath); err != nil {
t.Error(err)
}
}
func testResourceSCacheTestGetNotFound(t *testing.T) {
var reply *engine.ChargerProfile
if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,

View File

@@ -21,6 +21,7 @@ package v1
import (
"net/rpc"
"os"
"path"
"reflect"
"sort"
@@ -209,12 +210,14 @@ var (
testV1TSResetStorDb,
testV1TSStartEngine,
testV1TSRpcConn,
testV1ThresholdStartCPUProfiling,
testV1TSCacheThresholdBeforeLoad,
testV1TSFromFolder,
testV1TSCacheThresholdAfterLoad,
testV1TSGetThresholds,
testV1TSProcessEvent,
testV1TSGetThresholdsAfterProcess,
testV1ThresholdStopCPUProfiling,
testV1TSGetThresholdsAfterRestart,
testv1TSGetThresholdProfileIDs,
testv1TSGetThresholdProfileIDsCount,
@@ -303,6 +306,15 @@ func testV1TSRpcConn(t *testing.T) {
}
}
func testV1ThresholdStartCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := tSv1Rpc.Call(utils.CoreSv1StartCPUProfiling,
argPath, &reply); err != nil {
t.Error(err)
}
}
func testV1TSCacheThresholdBeforeLoad(t *testing.T) { // cache it with not found
var td engine.Threshold
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
@@ -991,6 +1003,32 @@ func testV1TSResetThresholdsWithoutTenant(t *testing.T) {
}
}
func testV1ThresholdStopCPUProfiling(t *testing.T) {
argPath := "/tmp/cpu.prof"
var reply string
if err := tSv1Rpc.Call(utils.CoreSv1StopCPUProfiling,
utils.EmptyString, &reply); err != nil {
t.Error(err)
}
file, err := os.Open(argPath)
if err != nil {
t.Error(err)
}
defer file.Close()
//compare the size
size, err := file.Stat()
if err != nil {
t.Error(err)
} else if size.Size() < int64(415) {
t.Errorf("Size of CPUProfile %v is lower that expected", size.Size())
}
//after we checked that CPUProfile was made successfully, can delete it
if err := os.Remove(argPath); err != nil {
t.Error(err)
}
}
func testThresholdSCacheProcessEventNotFound(t *testing.T) {
var ids []string
thEvent := &engine.ThresholdsArgsProcessEvent{

View File

@@ -1506,11 +1506,13 @@ const (
)
const (
CoreS = "CoreS"
CoreSv1 = "CoreSv1"
CoreSv1Status = "CoreSv1.Status"
CoreSv1Ping = "CoreSv1.Ping"
CoreSv1Sleep = "CoreSv1.Sleep"
CoreS = "CoreS"
CoreSv1 = "CoreSv1"
CoreSv1Status = "CoreSv1.Status"
CoreSv1Ping = "CoreSv1.Ping"
CoreSv1Sleep = "CoreSv1.Sleep"
CoreSv1StartCPUProfiling = "CoreSv1.StartCPUProfiling"
CoreSv1StopCPUProfiling = "CoreSv1.StopCPUProfiling"
)
// RouteS APIs