diff --git a/apier/v1/tprates.go b/apier/v1/tprates.go index 5aae835a1..92f047c8a 100644 --- a/apier/v1/tprates.go +++ b/apier/v1/tprates.go @@ -47,9 +47,10 @@ func (self *ApierV1) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error { return utils.NewErrMandatoryIeMissing(missing...) } if rs, err := self.StorDb.GetTPRates(attrs.TPid, attrs.ID); err != nil { - return utils.NewErrServerError(err) - } else if len(rs) == 0 { - return utils.ErrNotFound + if err.Error() != utils.ErrNotFound.Error() { + err = utils.NewErrServerError(err) + } + return err } else { *reply = *rs[0] } diff --git a/apier/v1/tprates_it_test.go b/apier/v1/tprates_it_test.go new file mode 100644 index 000000000..848375c03 --- /dev/null +++ b/apier/v1/tprates_it_test.go @@ -0,0 +1,240 @@ +// +build offline_TP + +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package v1 + +import ( + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" + "net/rpc" + "net/rpc/jsonrpc" + "path" + "reflect" + "testing" +) + +var ( + tpRateCfgPath string + tpRateCfg *config.CGRConfig + tpRateRPC *rpc.Client + tpRateDataDir = "/usr/share/cgrates" + tpRate *utils.TPRate + tpRateDelay int + tpRateConfigDIR string //run tests for specific configuration + +) + +var sTestsTPRates = []func(t *testing.T){ + testTPRatesInitCfg, + testTPRatesResetStorDb, + testTPRatesStartEngine, + testTPRatesRpcConn, + testTPRatesGetTPRateforeSet, + testTPRatesSetTPRate, + testTPRatesGetTPRateAfterSet, + testTPRatesGetTPRateIds, + testTPRatesUpdateTPRate, + testTPRatesGetTPRateAfterUpdate, + testTPRatesRemTPRate, + testTPRatesGetTPRateAfterRemove, + testTPRatesKillEngine, +} + +//Test start here +func TestTPRatesITMySql(t *testing.T) { + tpRateConfigDIR = "tutmysql" + for _, stest := range sTestsTPRates { + t.Run(tpRateConfigDIR, stest) + } +} + +func TestTPRatesITMongo(t *testing.T) { + tpRateConfigDIR = "tutmongo" + for _, stest := range sTestsTPRates { + t.Run(tpRateConfigDIR, stest) + } +} + +func TestTPRatesITPG(t *testing.T) { + tpRateConfigDIR = "tutpostgres" + for _, stest := range sTestsTPRates { + t.Run(tpRateConfigDIR, stest) + } +} + +func testTPRatesInitCfg(t *testing.T) { + var err error + tpRateCfgPath = path.Join(tpRateDataDir, "conf", "samples", tpRateConfigDIR) + tpRateCfg, err = config.NewCGRConfigFromFolder(tpRateCfgPath) + if err != nil { + t.Error(err) + } + tpRateCfg.DataFolderPath = tpRateDataDir // Share DataFolderPath through config towards StoreDb for Flush() + config.SetCgrConfig(tpRateCfg) + switch tpRateConfigDIR { + case "tutmongo": // Mongo needs more time to reset db, need to investigate + tpRateDelay = 2000 + default: + tpRateDelay = 1000 + } +} + +// Wipe out the cdr database +func testTPRatesResetStorDb(t *testing.T) { + if err := engine.InitStorDb(tpRateCfg); err != nil { + t.Fatal(err) + } +} + +// Start CGR Engine +func testTPRatesStartEngine(t *testing.T) { + if _, err := engine.StopStartEngine(tpRateCfgPath, tpRateDelay); err != nil { + t.Fatal(err) + } +} + +// Connect rpc client to rater +func testTPRatesRpcConn(t *testing.T) { + var err error + tpRateRPC, err = jsonrpc.Dial("tcp", tpRateCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal(err) + } +} + +func testTPRatesGetTPRateforeSet(t *testing.T) { + var reply *utils.TPRate + if err := tpRateRPC.Call("ApierV1.GetTPRate", &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + +func testTPRatesSetTPRate(t *testing.T) { + tpRate = &utils.TPRate{ + TPid: "TPidTpRate", + ID: "RT_FS_USERS", + RateSlots: []*utils.RateSlot{ + &utils.RateSlot{ + ConnectFee: 12, + Rate: 3, + RateUnit: "6s", + RateIncrement: "6s", + GroupIntervalStart: "0s", + }, + &utils.RateSlot{ + ConnectFee: 12, + Rate: 3, + RateUnit: "4s", + RateIncrement: "6s", + GroupIntervalStart: "1s", + }, + }, + } + var result string + if err := tpRateRPC.Call("ApierV1.SetTPRate", tpRate, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } +} + +func testTPRatesGetTPRateAfterSet(t *testing.T) { + var reply *utils.TPRate + if err := tpRateRPC.Call("ApierV1.GetTPRate", &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(tpRate, reply) { + t.Errorf("Expecting : %+v, received: %+v", tpRate, reply) + } +} + +func testTPRatesGetTPRateIds(t *testing.T) { + var result []string + expectedTPID := []string{"RT_FS_USERS"} + if err := tpRateRPC.Call("ApierV1.GetTPRateIds", &AttrGetTPRateIds{TPid: "TPidTpRate"}, &result); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expectedTPID, result) { + t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result) + } +} + +func testTPRatesUpdateTPRate(t *testing.T) { + var result string + tpRate.RateSlots = []*utils.RateSlot{ + &utils.RateSlot{ + ConnectFee: 12, + Rate: 3, + RateUnit: "6s", + RateIncrement: "6s", + GroupIntervalStart: "0s", + }, + &utils.RateSlot{ + ConnectFee: 12, + Rate: 10, + RateUnit: "4s", + RateIncrement: "6s", + GroupIntervalStart: "1s", + }, + &utils.RateSlot{ + ConnectFee: 5, + Rate: 10, + RateUnit: "4s", + RateIncrement: "6s", + GroupIntervalStart: "3s", + }, + } + if err := tpRateRPC.Call("ApierV1.SetTPRate", tpRate, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } +} + +func testTPRatesGetTPRateAfterUpdate(t *testing.T) { + var reply *utils.TPRate + if err := tpRateRPC.Call("ApierV1.GetTPRate", &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(tpRate, reply) { + t.Errorf("Expecting : %+v, received: %+v", tpRate, reply) + } + +} + +func testTPRatesRemTPRate(t *testing.T) { + var resp string + if err := tpRateRPC.Call("ApierV1.RemTPRate", &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } +} + +func testTPRatesGetTPRateAfterRemove(t *testing.T) { + var reply *utils.TPRate + if err := tpRateRPC.Call("ApierV1.GetTPRate", &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + +func testTPRatesKillEngine(t *testing.T) { + if err := engine.KillEngine(tpRateDelay); err != nil { + t.Error(err) + } +} diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go index 9888128d6..698ced6cd 100644 --- a/apier/v1/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -46,7 +46,7 @@ type AttrGetTPRatingProfileByLoadId struct { func (self *ApierV1) GetTPRatingProfilesByLoadId(attrs utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error { mndtryFlds := []string{"TPid", "LoadId"} if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory - mndtryFlds = append(mndtryFlds, "Tenant", "TOR", "Direction", "Subject") + mndtryFlds = append(mndtryFlds, "Tenant", "Category", "Direction", "Subject") } if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) @@ -68,7 +68,7 @@ func (self *ApierV1) GetTPRatingProfileLoadIds(attrs utils.AttrTPRatingProfileId } if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, utils.TPDistinctIds{"loadid"}, map[string]string{ "tenant": attrs.Tenant, - "tor": attrs.Category, + "category": attrs.Category, "direction": attrs.Direction, "subject": attrs.Subject, }, new(utils.Paginator)); err != nil { @@ -96,9 +96,10 @@ func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *uti return err } if rpfs, err := self.StorDb.GetTPRatingProfiles(tmpRpf); err != nil { - return utils.NewErrServerError(err) - } else if len(rpfs) == 0 { - return utils.ErrNotFound + if err.Error() != utils.ErrNotFound.Error() { + err = utils.NewErrServerError(err) + } + return err } else { *reply = *rpfs[0] } diff --git a/apier/v1/tpratingprofiles_it_test.go b/apier/v1/tpratingprofiles_it_test.go new file mode 100644 index 000000000..a01e02de7 --- /dev/null +++ b/apier/v1/tpratingprofiles_it_test.go @@ -0,0 +1,262 @@ +// +build offline_TP + +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package v1 + +import ( + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" + "net/rpc" + "net/rpc/jsonrpc" + "path" + "reflect" + "testing" +) + +var ( + tpRatingProfileCfgPath string + tpRatingProfileCfg *config.CGRConfig + tpRatingProfileRPC *rpc.Client + tpRatingProfileDataDir = "/usr/share/cgrates" + tpRatingProfile *utils.TPRatingProfile + tpRatingProfileDelay int + tpRatingProfileConfigDIR string //run tests for specific configuration + tpRatingProfileID = "RPrf:*out:Tenant1:Category:Subject" +) + +var sTestsTPRatingProfiles = []func(t *testing.T){ + testTPRatingProfilesInitCfg, + testTPRatingProfilesResetStorDb, + testTPRatingProfilesStartEngine, + testTPRatingProfilesRpcConn, + testTPRatingProfilesGetTPRatingProfileBeforeSet, + testTPRatingProfilesSetTPRatingProfile, + testTPRatingProfilesGetTPRatingProfileAfterSet, + testTPRatingProfilesGetTPRatingProfileLoadIds, + testTPRatingProfilesUpdateTPRatingProfile, + testTPRatingProfilesGetTPRatingProfileAfterUpdate, + testTPRatingProfilesRemTPRatingProfile, + testTPRatingProfilesGetTPRatingProfileAfterRemove, + testTPRatingProfilesKillEngine, +} + +//Test start here +func TestTPRatingProfilesITMySql(t *testing.T) { + tpRatingProfileConfigDIR = "tutmysql" + for _, stest := range sTestsTPRatingProfiles { + t.Run(tpRatingProfileConfigDIR, stest) + } +} + +func TestTPRatingProfilesITMongo(t *testing.T) { + tpRatingProfileConfigDIR = "tutmongo" + for _, stest := range sTestsTPRatingProfiles { + t.Run(tpRatingProfileConfigDIR, stest) + } +} + +func TestTPRatingProfilesITPG(t *testing.T) { + tpRatingProfileConfigDIR = "tutpostgres" + for _, stest := range sTestsTPRatingProfiles { + t.Run(tpRatingProfileConfigDIR, stest) + } +} + +func testTPRatingProfilesInitCfg(t *testing.T) { + var err error + tpRatingProfileCfgPath = path.Join(tpRatingProfileDataDir, "conf", "samples", tpRatingProfileConfigDIR) + tpRatingProfileCfg, err = config.NewCGRConfigFromFolder(tpRatingProfileCfgPath) + if err != nil { + t.Error(err) + } + tpRatingProfileCfg.DataFolderPath = tpRatingProfileDataDir // Share DataFolderPath through config towards StoreDb for Flush() + config.SetCgrConfig(tpRatingProfileCfg) + switch tpRatingProfileConfigDIR { + case "tutmongo": // Mongo needs more time to reset db, need to investigate + tpRatingProfileDelay = 2000 + default: + tpRatingProfileDelay = 1000 + } +} + +// Wipe out the cdr database +func testTPRatingProfilesResetStorDb(t *testing.T) { + if err := engine.InitStorDb(tpRatingProfileCfg); err != nil { + t.Fatal(err) + } +} + +// Start CGR Engine +func testTPRatingProfilesStartEngine(t *testing.T) { + if _, err := engine.StopStartEngine(tpRatingProfileCfgPath, tpRatingProfileDelay); err != nil { + t.Fatal(err) + } +} + +// Connect rpc client to rater +func testTPRatingProfilesRpcConn(t *testing.T) { + var err error + tpRatingProfileRPC, err = jsonrpc.Dial("tcp", tpRatingProfileCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal(err) + } +} + +func testTPRatingProfilesGetTPRatingProfileBeforeSet(t *testing.T) { + var reply *utils.TPRatingProfile + if err := tpRatingProfileRPC.Call("ApierV1.GetTPRatingProfile", &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileId: tpRatingProfileID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + +func testTPRatingProfilesSetTPRatingProfile(t *testing.T) { + tpRatingProfile = &utils.TPRatingProfile{ + TPid: "TPRProf1", + LoadId: "RPrf", + Direction: "*out", + Tenant: "Tenant1", + Category: "Category", + Subject: "Subject", + RatingPlanActivations: []*utils.TPRatingActivation{ + &utils.TPRatingActivation{ + ActivationTime: "2014-07-29T15:00:00Z", + RatingPlanId: "PlanOne", + FallbackSubjects: "FallBack", + CdrStatQueueIds: "RandomId", + }, + &utils.TPRatingActivation{ + ActivationTime: "2015-07-29T10:00:00Z", + RatingPlanId: "PlanTwo", + FallbackSubjects: "FallOut", + CdrStatQueueIds: "RandomIdTwo", + }, + }, + } + var result string + if err := tpRatingProfileRPC.Call("ApierV1.SetTPRatingProfile", tpRatingProfile, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } +} + +func testTPRatingProfilesGetTPRatingProfileAfterSet(t *testing.T) { + var respond *utils.TPRatingProfile + if err := tpRatingProfileRPC.Call("ApierV1.GetTPRatingProfile", &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileId: tpRatingProfileID}, &respond); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.TPid, respond.TPid) + } else if !reflect.DeepEqual(tpRatingProfile.LoadId, respond.LoadId) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.LoadId, respond.LoadId) + } else if !reflect.DeepEqual(tpRatingProfile.Direction, respond.Direction) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Direction, respond.Direction) + } else if !reflect.DeepEqual(tpRatingProfile.Tenant, respond.Tenant) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Tenant, respond.Tenant) + } else if !reflect.DeepEqual(tpRatingProfile.Category, respond.Category) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Category, respond.Category) + } else if !reflect.DeepEqual(tpRatingProfile.Subject, respond.Subject) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Subject, respond.Subject) + } else if !reflect.DeepEqual(len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) { + t.Errorf("Expecting : %+v, received: %+v", len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) + } +} + +func testTPRatingProfilesGetTPRatingProfileLoadIds(t *testing.T) { + var result []string + expected := []string{"RPrf"} + if err := tpRatingProfileRPC.Call("ApierV1.GetTPRatingProfileLoadIds", &utils.AttrTPRatingProfileIds{TPid: tpRatingProfile.TPid, Tenant: tpRatingProfile.Tenant, Category: tpRatingProfile.Category, Direction: tpRatingProfile.Direction, Subject: tpRatingProfile.Subject}, &result); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, result) { + t.Errorf("Expecting: %+v, received: %+v", expected, result) + } +} + +func testTPRatingProfilesUpdateTPRatingProfile(t *testing.T) { + var result string + tpRatingProfile.RatingPlanActivations = []*utils.TPRatingActivation{ + &utils.TPRatingActivation{ + ActivationTime: "2014-07-29T15:00:00Z", + RatingPlanId: "PlanOne", + FallbackSubjects: "FallBack", + CdrStatQueueIds: "RandomId", + }, + &utils.TPRatingActivation{ + ActivationTime: "2015-07-29T10:00:00Z", + RatingPlanId: "PlanTwo", + FallbackSubjects: "FallOut", + CdrStatQueueIds: "RandomIdTwo", + }, + &utils.TPRatingActivation{ + ActivationTime: "2017-07-29T10:00:00Z", + RatingPlanId: "BackupPlan", + FallbackSubjects: "Retreat", + CdrStatQueueIds: "DefenseID", + }, + } + if err := tpRatingProfileRPC.Call("ApierV1.SetTPRatingProfile", tpRatingProfile, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } +} + +func testTPRatingProfilesGetTPRatingProfileAfterUpdate(t *testing.T) { + var respond *utils.TPRatingProfile + if err := tpRatingProfileRPC.Call("ApierV1.GetTPRatingProfile", &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileId: tpRatingProfileID}, &respond); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.TPid, respond.TPid) + } else if !reflect.DeepEqual(tpRatingProfile.LoadId, respond.LoadId) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.LoadId, respond.LoadId) + } else if !reflect.DeepEqual(tpRatingProfile.Direction, respond.Direction) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Direction, respond.Direction) + } else if !reflect.DeepEqual(tpRatingProfile.Tenant, respond.Tenant) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Tenant, respond.Tenant) + } else if !reflect.DeepEqual(tpRatingProfile.Category, respond.Category) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Category, respond.Category) + } else if !reflect.DeepEqual(tpRatingProfile.Subject, respond.Subject) { + t.Errorf("Expecting : %+v, received: %+v", tpRatingProfile.Subject, respond.Subject) + } else if !reflect.DeepEqual(len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) { + t.Errorf("Expecting : %+v, received: %+v", len(tpRatingProfile.RatingPlanActivations), len(respond.RatingPlanActivations)) + } +} + +func testTPRatingProfilesRemTPRatingProfile(t *testing.T) { + var resp string + if err := tpRatingProfileRPC.Call("ApierV1.RemTPRatingProfile", &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileId: tpRatingProfile.GetRatingProfilesId()}, &resp); err != nil { + t.Error(err) + } else if resp != utils.OK { + t.Error("Unexpected reply returned", resp) + } +} + +func testTPRatingProfilesGetTPRatingProfileAfterRemove(t *testing.T) { + var respond *utils.TPRatingProfile + if err := tpRatingProfileRPC.Call("ApierV1.GetTPRatingProfile", &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileId: tpRatingProfileID}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + +func testTPRatingProfilesKillEngine(t *testing.T) { + if err := engine.KillEngine(tpRatingProfileDelay); err != nil { + t.Error(err) + } +} diff --git a/apier/v1/tpresources_it_test.go b/apier/v1/tpresources_it_test.go index 97190a87e..7d645577d 100644 --- a/apier/v1/tpresources_it_test.go +++ b/apier/v1/tpresources_it_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build offline_TP /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments @@ -89,7 +89,7 @@ func testTPResInitCfg(t *testing.T) { config.SetCgrConfig(tpResCfg) switch tpResConfigDIR { case "tutmongo": // Mongo needs more time to reset db, need to investigate - tpResDelay = 4000 + tpResDelay = 2000 default: tpResDelay = 1000 } diff --git a/apier/v1/tpsharedgroups_it_test.go b/apier/v1/tpsharedgroups_it_test.go index 0f6e311a6..ea17a923c 100644 --- a/apier/v1/tpsharedgroups_it_test.go +++ b/apier/v1/tpsharedgroups_it_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build offline_TP /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments @@ -90,9 +90,9 @@ func testTPSharedGroupsInitCfg(t *testing.T) { config.SetCgrConfig(tpSharedGroupCfg) switch tpSharedGroupConfigDIR { case "tutmongo": // Mongo needs more time to reset db - tpSharedGroupDelay = 4000 - default: tpSharedGroupDelay = 2000 + default: + tpSharedGroupDelay = 1000 } } diff --git a/apier/v1/tpstats_it_test.go b/apier/v1/tpstats_it_test.go index 4d5f46f84..28e3e9a26 100644 --- a/apier/v1/tpstats_it_test.go +++ b/apier/v1/tpstats_it_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build offline_TP /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments @@ -89,7 +89,7 @@ func testTPStatsInitCfg(t *testing.T) { config.SetCgrConfig(tpStatCfg) switch tpStatConfigDIR { case "tutmongo": // Mongo needs more time to reset db - tpStatDelay = 4000 + tpStatDelay = 2000 default: tpStatDelay = 1000 } diff --git a/apier/v1/tptimings_it_test.go b/apier/v1/tptimings_it_test.go index c98604151..e58df05e0 100644 --- a/apier/v1/tptimings_it_test.go +++ b/apier/v1/tptimings_it_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build offline_TP /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments @@ -90,9 +90,9 @@ func testTPTimingsInitCfg(t *testing.T) { config.SetCgrConfig(tpTimingCfg) switch tpTimingConfigDIR { case "tutmongo": // Mongo needs more time to reset db - tpTimingDelay = 4000 - default: tpTimingDelay = 2000 + default: + tpTimingDelay = 1000 } } diff --git a/apier/v1/tpusers_it_test.go b/apier/v1/tpusers_it_test.go index 27a1c891d..1e797e8e0 100644 --- a/apier/v1/tpusers_it_test.go +++ b/apier/v1/tpusers_it_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build offline_TP /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments @@ -90,9 +90,9 @@ func testTPUsersInitCfg(t *testing.T) { config.SetCgrConfig(tpUserCfg) switch tpUserConfigDIR { case "tutmongo": // Mongo needs more time to reset db - tpUserDelay = 4000 - default: tpUserDelay = 2000 + default: + tpUserDelay = 1000 } } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index a7263cab0..fdf8c4de5 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -221,7 +221,6 @@ func (self *SQLStorage) SetTPTimings(timings []*utils.ApierTPTiming) error { tx := self.db.Begin() for _, timing := range timings { - utils.Logger.Debug(fmt.Sprintf("#1(set) Id care trimite %s", timing.ID)) if err := tx.Where(&TpTiming{Tpid: timing.TPid, Tag: timing.ID}).Delete(TpTiming{}).Error; err != nil { tx.Rollback() return err @@ -1171,8 +1170,6 @@ func (self *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { var tpTimings TpTimings q := self.db.Where("tpid = ?", tpid) - utils.Logger.Debug(fmt.Sprintf("#1 Id care trimite %s", id)) - utils.Logger.Debug(fmt.Sprintf("#1 TPId care trimite %s", tpid)) if len(id) != 0 { q = q.Where("tag = ?", id) } @@ -1180,7 +1177,6 @@ func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e return nil, err } ts := tpTimings.AsTPTimings() - utils.Logger.Debug(fmt.Sprintf("#2 ce gaseste : %s", ts)) if len(ts) == 0 { return ts, utils.ErrNotFound } diff --git a/offline_tp_test.sh b/offline_tp_test.sh new file mode 100755 index 000000000..c2c7cc216 --- /dev/null +++ b/offline_tp_test.sh @@ -0,0 +1,6 @@ +./test.sh +gen=$? +echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline_TP' +go test github.com/cgrates/cgrates/apier/v1 -tags=offline_TP + +exit $gen