From f63dc62519aeccea20c6e94fb3c7ef36e8c9b15a Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 8 Dec 2020 15:04:58 +0200 Subject: [PATCH] Updated integration tests --- apier/v1/actionprofiles_it_test.go | 18 ++++++++++++------ apier/v1/remote_it_test.go | 4 ++-- apier/v1/resourcesv1_it_test.go | 16 ++++------------ .../cdrsv_failover_internal/cgrates.json | 1 + .../samples/cdrsv_failover_mongo/cgrates.json | 1 + .../samples/cdrsv_failover_mysql/cgrates.json | 3 ++- engine/resources.go | 2 +- general_tests/cdrs_post_failover_it_test.go | 10 ++++++++++ general_tests/poster_it_test.go | 2 +- migrator/storage_mongo_stordb.go | 2 +- services/resources.go | 3 ++- 11 files changed, 37 insertions(+), 25 deletions(-) diff --git a/apier/v1/actionprofiles_it_test.go b/apier/v1/actionprofiles_it_test.go index e697e1dfe..54a1e02ca 100644 --- a/apier/v1/actionprofiles_it_test.go +++ b/apier/v1/actionprofiles_it_test.go @@ -127,37 +127,37 @@ func testActionSGetActionProfile(t *testing.T) { FilterIDs: []string{}, Weight: 10, Schedule: utils.ASAP, - AccountIDs: map[string]struct{}{"1001": struct{}{}, "1002": struct{}{}}, + AccountIDs: utils.StringSet{"1001": {}, "1002": {}}, Actions: []*engine.APAction{ - &engine.APAction{ + { ID: "TOPUP", FilterIDs: []string{}, Type: "*topup", Path: "~*balance.TestBalance.Value", Value: config.NewRSRParsersMustCompile("10", actPrfCfg.GeneralCfg().RSRSep), }, - &engine.APAction{ + { ID: "SET_BALANCE_TEST_DATA", FilterIDs: []string{}, Type: "*set_balance", Path: "~*balance.TestDataBalance.Type", Value: config.NewRSRParsersMustCompile("*data", actPrfCfg.GeneralCfg().RSRSep), }, - &engine.APAction{ + { ID: "TOPUP_TEST_DATA", FilterIDs: []string{}, Type: "*topup", Path: "~*balance.TestDataBalance.Value", Value: config.NewRSRParsersMustCompile("1024", actPrfCfg.GeneralCfg().RSRSep), }, - &engine.APAction{ + { ID: "SET_BALANCE_TEST_VOICE", FilterIDs: []string{}, Type: "*set_balance", Path: "~*balance.TestVoiceBalance.Type", Value: config.NewRSRParsersMustCompile("*voice", actPrfCfg.GeneralCfg().RSRSep), }, - &engine.APAction{ + { ID: "TOPUP_TEST_VOICE", FilterIDs: []string{}, Type: "*topup", @@ -166,6 +166,12 @@ func testActionSGetActionProfile(t *testing.T) { }, }, } + if *encoding == utils.MetaGOB { + expected.FilterIDs = nil + for i := range expected.Actions { + expected.Actions[i].FilterIDs = nil + } + } var reply *engine.ActionProfile if err := actSRPC.Call(utils.APIerSv1GetActionProfile, utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ONE_TIME_ACT"}}, &reply); err != nil { diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index 6eff852ba..a46634daf 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -677,7 +677,7 @@ func testInternalRemoteITGetDispatcherHost(t *testing.T) { func testInternalRemoteITGetRouteProfile(t *testing.T) { var rcv *engine.RateProfile if err := internalRPC.Call(utils.APIerSv1GetRateProfile, - &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}, + &utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}}, &rcv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -754,7 +754,7 @@ func testInternalRemoteITGetRouteProfile(t *testing.T) { var rPfrg *engine.RateProfile if err := internalRPC.Call(utils.APIerSv1GetRateProfile, - &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}, + &utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}}, &rPfrg); err != nil { t.Error(err) } else if !reflect.DeepEqual(rPrf.RateProfileWithOpts.RateProfile, rPfrg) { diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 77e5557c2..d4e35794a 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -558,11 +558,7 @@ func testV1RsReleaseResource(t *testing.T) { t.Errorf("Resources: %+v", rs) } if rs == nil { - t.Errorf("Expecting rs to not be nil") - // rs shoud not be nil so exit function - // to avoid nil segmentation fault; - // if this happens try to run this test manualy - return + t.Fatal("Expecting rs to not be nil") } // make sure Resource1 have no more active resources for _, r := range *rs { @@ -636,11 +632,7 @@ func testV1RsDBStore(t *testing.T) { t.Errorf("Resources: %+v", rs) } if rs == nil { - t.Errorf("Expecting rs to not be nil") - // rs shoud not be nil so exit function - // to avoid nil segmentation fault; - // if this happens try to run this test manualy - return + t.Fatal("Expecting rs to not be nil") } // count resources before restart for _, r := range *rs { @@ -690,7 +682,7 @@ func testV1RsDBStore(t *testing.T) { t.Errorf("Unexpected resource: %+v", r) } case "ResGroup2": - if len(r.Usages) != 3 || len(r.TTLIdx) != 3 { + if len(r.Usages) != 4 || len(r.TTLIdx) != 4 { t.Errorf("Unexpected resource: %s", utils.ToJSON(r)) } } @@ -914,7 +906,7 @@ func testV1RsAllocateUnlimited(t *testing.T) { Tenant: "cgrates.org", ID: "RES_ULTIMITED", Usages: map[string]*engine.ResourceUsage{ - "651a8db2-4f67-4cf8-b622-169e8a482e51": &engine.ResourceUsage{ + "651a8db2-4f67-4cf8-b622-169e8a482e51": { Tenant: "cgrates.org", ID: "651a8db2-4f67-4cf8-b622-169e8a482e51", Units: 1, diff --git a/data/conf/samples/cdrsv_failover_internal/cgrates.json b/data/conf/samples/cdrsv_failover_internal/cgrates.json index da2b1bf9f..1c7ef10d0 100644 --- a/data/conf/samples/cdrsv_failover_internal/cgrates.json +++ b/data/conf/samples/cdrsv_failover_internal/cgrates.json @@ -9,6 +9,7 @@ "node_id": "TestFailCDRS", "poster_attempts": 1, // number of attempts before considering post request failed (eg: *http_post, CDR exports) "failed_posts_ttl": "1s", // time to wait before writing the failed posts in a single file + "failed_posts_dir": "/tmp/failed_posts" // directory path where we store failed requests }, "stor_db": { diff --git a/data/conf/samples/cdrsv_failover_mongo/cgrates.json b/data/conf/samples/cdrsv_failover_mongo/cgrates.json index 013c8b9de..78b24b130 100644 --- a/data/conf/samples/cdrsv_failover_mongo/cgrates.json +++ b/data/conf/samples/cdrsv_failover_mongo/cgrates.json @@ -8,6 +8,7 @@ "log_level": 7, "poster_attempts": 1, // number of attempts before considering post request failed (eg: *http_post, CDR exports) "failed_posts_ttl": "1s", // time to wait before writing the failed posts in a single file + "failed_posts_dir": "/tmp/failed_posts" // directory path where we store failed requests }, "data_db": { diff --git a/data/conf/samples/cdrsv_failover_mysql/cgrates.json b/data/conf/samples/cdrsv_failover_mysql/cgrates.json index bf084d977..176360583 100644 --- a/data/conf/samples/cdrsv_failover_mysql/cgrates.json +++ b/data/conf/samples/cdrsv_failover_mysql/cgrates.json @@ -7,7 +7,8 @@ "general": { "log_level": 7, "poster_attempts": 1, // number of attempts before considering post request failed (eg: *http_post, CDR exports) - "failed_posts_ttl": "1s" // time to wait before writing the failed posts in a single file + "failed_posts_ttl": "1s", // time to wait before writing the failed posts in a single file + "failed_posts_dir": "/tmp/failed_posts" // directory path where we store failed requests }, diff --git a/engine/resources.go b/engine/resources.go index 4b48e7e05..dfb5b788c 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -383,7 +383,7 @@ func (rS *ResourceService) storeResources() { break // no more keys, backup completed } if rIf, ok := Cache.Get(utils.CacheResources, rID); !ok || rIf == nil { - utils.Logger.Warning(fmt.Sprintf(" failed retrieving from cache resource with ID: %s", rID)) + utils.Logger.Warning(fmt.Sprintf("<%s> failed retrieving from cache resource with ID: %s", utils.ResourceS, rID)) } else if err := rS.StoreResource(rIf.(*Resource)); err != nil { failedRIDs = append(failedRIDs, rID) // record failure so we can schedule it for next backup } diff --git a/general_tests/cdrs_post_failover_it_test.go b/general_tests/cdrs_post_failover_it_test.go index f64146eed..f0fcc98a8 100644 --- a/general_tests/cdrs_post_failover_it_test.go +++ b/general_tests/cdrs_post_failover_it_test.go @@ -23,6 +23,7 @@ package general_tests import ( "io/ioutil" "net/rpc" + "os" "path" "testing" "time" @@ -78,6 +79,12 @@ func testCDRsPostFailoverInitConfig(t *testing.T) { if cdrsPostFailCfg, err = config.NewCGRConfigFromPath(cdrsPostFailCfgPath); err != nil { t.Fatal("Got config error: ", err.Error()) } + if err = os.RemoveAll(cdrsPostFailCfg.GeneralCfg().FailedPostsDir); err != nil { + t.Error(err) + } + if err = os.MkdirAll(cdrsPostFailCfg.GeneralCfg().FailedPostsDir, 0755); err != nil { + t.Error(err) + } } func testCDRsPostFailoverInitDataDb(t *testing.T) { @@ -206,6 +213,9 @@ func testCDRsPostFailoverToFile(t *testing.T) { } func testCDRsPostFailoverKillEngine(t *testing.T) { + if err = os.RemoveAll(cdrsPostFailCfg.GeneralCfg().FailedPostsDir); err != nil { + t.Error(err) + } if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) } diff --git a/general_tests/poster_it_test.go b/general_tests/poster_it_test.go index 9dbe6f35d..a0a25c3bb 100644 --- a/general_tests/poster_it_test.go +++ b/general_tests/poster_it_test.go @@ -200,7 +200,7 @@ func testPosterITAMQPv1(t *testing.T) { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } // verify if acction was executed - time.Sleep(100 * time.Millisecond) + time.Sleep(150 * time.Millisecond) ev, err := testPosterReadFolder(utils.MetaAMQPV1jsonMap) if err != nil { t.Fatal(err) diff --git a/migrator/storage_mongo_stordb.go b/migrator/storage_mongo_stordb.go index 795f55251..655358c67 100644 --- a/migrator/storage_mongo_stordb.go +++ b/migrator/storage_mongo_stordb.go @@ -94,7 +94,7 @@ func (v1ms *mongoStorDBMigrator) createV1SMCosts() (err error) { v1ms.mgoDB.DB().Collection(utils.OldSMCosts).Drop(v1ms.mgoDB.GetContext()) v1ms.mgoDB.DB().Collection(utils.SessionCostsTBL).Drop(v1ms.mgoDB.GetContext()) return v1ms.mgoDB.DB().RunCommand(v1ms.mgoDB.GetContext(), - bson.D{{Key: "create", Value: utils.OldSMCosts}, {Key: "size", Value: 1024}}).Err() + bson.D{{Key: "create", Value: utils.OldSMCosts}, {Key: "size", Value: 1024}, {Key: "capped", Value: true}}).Err() } //get diff --git a/services/resources.go b/services/resources.go index d79930676..f01122a2d 100644 --- a/services/resources.go +++ b/services/resources.go @@ -72,7 +72,7 @@ func (reS *ResourceService) Start() (err error) { if reS.IsRunning() { return utils.ErrServiceAlreadyRunning } - + reS.srvDep[utils.DataDB].Add(1) <-reS.cacheS.GetPrecacheChannel(utils.CacheResourceProfiles) <-reS.cacheS.GetPrecacheChannel(utils.CacheResources) <-reS.cacheS.GetPrecacheChannel(utils.CacheResourceFilterIndexes) @@ -110,6 +110,7 @@ func (reS *ResourceService) Reload() (err error) { // Shutdown stops the service func (reS *ResourceService) Shutdown() (err error) { + defer reS.srvDep[utils.DataDB].Done() reS.Lock() defer reS.Unlock() if err = reS.reS.Shutdown(); err != nil {