From d3968b50c0b9ec5d65d07b4fe7b8525267278612 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Fri, 25 Jun 2021 16:44:48 +0300 Subject: [PATCH] INtegrated CPUProfile in other tests --- apier/v1/dispatcher_it_test.go | 38 +++++++++++++++++++++++++++++++++ apier/v1/filters_it_test.go | 38 +++++++++++++++++++++++++++++++++ apier/v1/remote_it_test.go | 2 +- apier/v1/resourcesv1_it_test.go | 38 +++++++++++++++++++++++++++++++++ apier/v1/thresholds_it_test.go | 38 +++++++++++++++++++++++++++++++++ utils/consts.go | 12 ++++++----- 6 files changed, 160 insertions(+), 6 deletions(-) diff --git a/apier/v1/dispatcher_it_test.go b/apier/v1/dispatcher_it_test.go index 5ec985591..9015ad043 100644 --- a/apier/v1/dispatcher_it_test.go +++ b/apier/v1/dispatcher_it_test.go @@ -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) diff --git a/apier/v1/filters_it_test.go b/apier/v1/filters_it_test.go index df8a4b211..e4ca0a414 100644 --- a/apier/v1/filters_it_test.go +++ b/apier/v1/filters_it_test.go @@ -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) + } +} diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index e03c74c50..6ef6ec67e 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -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() diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index e8fa691d8..0155b5f5d 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -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, diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index 60c2ce1fe..e2e02707d 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -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{ diff --git a/utils/consts.go b/utils/consts.go index 9819d5d00..fa81ef249 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -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