How to use Pause method of utils Package

Best Rod code snippet using utils.Pause

sessionpause_it_test.go

Source:sessionpause_it_test.go Github

copy

Full Screen

...27 "github.com/cgrates/cgrates/sessions"28 "github.com/cgrates/cgrates/utils"29)30var (31 sesPauseCfgDir string32 sesPauseCfgPath string33 sesPauseCfg *config.CGRConfig34 sesPauseRPC *rpc.Client35 sesPauseTests = []func(t *testing.T){36 testSesPauseItLoadConfig,37 testSesPauseItResetDataDB,38 testSesPauseItResetStorDb,39 testSesPauseItStartEngine,40 testSesPauseItRPCConn,41 testSesPauseItLoadFromFolder,42 testSesPauseItAllPause,43 testSesPauseItInitPause,44 testSesPauseItInitUpdatePause,45 testSesPauseItUpdatePause,46 testSesPauseItStopCgrEngine,47 }48)49func TestSesPauseItSessions(t *testing.T) {50 switch *dbType {51 case utils.MetaInternal:52 sesPauseCfgDir = "tutinternal"53 case utils.MetaMySQL:54 sesPauseCfgDir = "tutmysql"55 case utils.MetaMongo:56 sesPauseCfgDir = "tutmongo"57 case utils.MetaPostgres:58 t.SkipNow()59 default:60 t.Fatal("Unknown Database type")61 }62 for _, stest := range sesPauseTests {63 t.Run(sesPauseCfgDir, stest)64 }65}66func testSesPauseItLoadConfig(t *testing.T) {67 sesPauseCfgPath = path.Join(*dataDir, "conf", "samples", sesPauseCfgDir)68 if sesPauseCfg, err = config.NewCGRConfigFromPath(sesPauseCfgPath); err != nil {69 t.Error(err)70 }71}72func testSesPauseItResetDataDB(t *testing.T) {73 if err := engine.InitDataDb(sesPauseCfg); err != nil {74 t.Fatal(err)75 }76}77func testSesPauseItResetStorDb(t *testing.T) {78 if err := engine.InitStorDb(sesPauseCfg); err != nil {79 t.Fatal(err)80 }81}82func testSesPauseItStartEngine(t *testing.T) {83 if _, err := engine.StopStartEngine(sesPauseCfgPath, *waitRater); err != nil {84 t.Fatal(err)85 }86}87func testSesPauseItRPCConn(t *testing.T) {88 var err error89 sesPauseRPC, err = newRPCClient(sesPauseCfg.ListenCfg())90 if err != nil {91 t.Fatal(err)92 }93}94func testSesPauseItLoadFromFolder(t *testing.T) {95 var reply string96 attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}97 if err := sesPauseRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {98 t.Error(err)99 }100 time.Sleep(100 * time.Millisecond)101}102func testSesPauseItInitSession(t *testing.T, cgrID string, chargeable bool, usage time.Duration) {103 args1 := &sessions.V1InitSessionArgs{104 InitSession: true,105 CGREvent: &utils.CGREvent{106 Tenant: "cgrates.org",107 Event: map[string]interface{}{108 utils.CGRID: cgrID,109 utils.Category: utils.Call,110 utils.ToR: utils.MetaVoice,111 utils.OriginID: "TestDebitIterval",112 utils.RequestType: utils.MetaPrepaid,113 utils.AccountField: "1001",114 utils.Subject: "1001",115 utils.Destination: "1002",116 utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),117 utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),118 utils.Usage: usage,119 },120 APIOpts: map[string]interface{}{121 utils.OptsDebitInterval: "0s",122 utils.OptsChargeable: chargeable,123 },124 },125 }126 var rply1 sessions.V1InitSessionReply127 if err := sesPauseRPC.Call(utils.SessionSv1InitiateSession,128 args1, &rply1); err != nil {129 t.Error(err)130 return131 } else if rply1.MaxUsage != nil && *rply1.MaxUsage != usage {132 t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage)133 }134}135func testSesPauseItUpdateSession(t *testing.T, cgrID string, chargeable bool, usage time.Duration) {136 updtArgs := &sessions.V1UpdateSessionArgs{137 UpdateSession: true,138 CGREvent: &utils.CGREvent{139 Tenant: "cgrates.org",140 Event: map[string]interface{}{141 utils.CGRID: cgrID,142 utils.Category: utils.Call,143 utils.ToR: utils.MetaVoice,144 utils.OriginID: "TestDebitIterval",145 utils.RequestType: utils.MetaPrepaid,146 utils.AccountField: "1001",147 utils.Subject: "1001",148 utils.Destination: "1002",149 utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),150 utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),151 utils.Usage: usage,152 },153 APIOpts: map[string]interface{}{154 utils.OptsChargeable: chargeable,155 },156 },157 }158 var updtRpl sessions.V1UpdateSessionReply159 if err := sesPauseRPC.Call(utils.SessionSv1UpdateSession, updtArgs, &updtRpl); err != nil {160 t.Error(err)161 }162 if updtRpl.MaxUsage == nil || *updtRpl.MaxUsage != usage {163 t.Errorf("Expecting : %+v, received: %+v", usage, updtRpl.MaxUsage)164 }165}166func testSesPauseItTerminateSession(t *testing.T, cgrID string, chargeable bool, usage time.Duration) {167 args := &sessions.V1TerminateSessionArgs{168 TerminateSession: true,169 CGREvent: &utils.CGREvent{170 Tenant: "cgrates.org",171 Event: map[string]interface{}{172 utils.CGRID: cgrID,173 utils.Category: utils.Call,174 utils.ToR: utils.MetaVoice,175 utils.OriginID: "TestDebitIterval",176 utils.RequestType: utils.MetaPrepaid,177 utils.AccountField: "1001",178 utils.Subject: "1002",179 utils.Destination: "1002",180 utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),181 utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),182 utils.Usage: usage,183 },184 APIOpts: map[string]interface{}{185 utils.OptsChargeable: chargeable,186 },187 },188 }189 var rply string190 if err := sesPauseRPC.Call(utils.SessionSv1TerminateSession,191 args, &rply); err != nil {192 t.Error(err)193 }194 if rply != utils.OK {195 t.Errorf("Unexpected reply: %s", rply)196 }197 if err := sesPauseRPC.Call(utils.SessionSv1ProcessCDR, &utils.CGREvent{198 Tenant: "cgrates.org",199 ID: "testSesPauseItProccesCDR",200 Event: map[string]interface{}{201 utils.CGRID: cgrID,202 utils.Category: utils.Call,203 utils.ToR: utils.MetaVoice,204 utils.OriginID: "TestDebitIterval",205 utils.RequestType: utils.MetaPrepaid,206 utils.AccountField: "1001",207 utils.Subject: "1002",208 utils.Destination: "1002",209 utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),210 utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),211 utils.Usage: usage,212 },213 }, &rply); err != nil {214 t.Error(err)215 } else if rply != utils.OK {216 t.Errorf("Received reply: %s", rply)217 }218}219func testSesPauseItAllPause(t *testing.T) {220 cgrID := "1b676c7583ceb27ad7c991ded73b2417faa29a6a"221 testSesPauseItInitSession(t, cgrID, false, time.Second)222 testSesPauseItUpdateSession(t, cgrID, false, 2*time.Second)223 testSesPauseItTerminateSession(t, cgrID, false, 5*time.Second)224 time.Sleep(20 * time.Millisecond)225 var cdrs []*engine.ExternalCDR226 req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}}227 if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil {228 t.Error("Unexpected error: ", err.Error())229 }230 exp := []*engine.ExternalCDR{{231 CGRID: cgrID,232 RunID: "*default",233 OrderID: 0,234 OriginHost: "",235 Source: "",236 OriginID: "TestDebitIterval",237 ToR: "*voice",238 RequestType: "*prepaid",239 Tenant: "cgrates.org",240 Category: "call",241 Account: "1001",242 Subject: "1001",243 Destination: "1002",244 SetupTime: "2018-01-07 17:00:00 +0000 UTC",245 AnswerTime: "2018-01-07 17:00:10 +0000 UTC",246 Usage: "5s",247 ExtraFields: map[string]string{},248 CostSource: "*sessions",249 Cost: 0,250 CostDetails: "",251 ExtraInfo: "",252 PreRated: false,253 }}254 if len(cdrs) == 0 {255 t.Fatal("No cdrs returned")256 }257 cdrs[0].OrderID = 0258 cdString := cdrs[0].CostDetails259 cdrs[0].CostDetails = ""260 var val time.Time261 if val, err = utils.ParseTimeDetectLayout(cdrs[0].AnswerTime, ""); err != nil {262 t.Fatal(err)263 }264 cdrs[0].AnswerTime = val.UTC().String()265 if val, err = utils.ParseTimeDetectLayout(cdrs[0].SetupTime, ""); err != nil {266 t.Fatal(err)267 }268 cdrs[0].SetupTime = val.UTC().String()269 if !reflect.DeepEqual(exp, cdrs) {270 t.Errorf("Expected %s \n received: %s", utils.ToJSON(exp), utils.ToJSON(cdrs))271 }272 var cd engine.EventCost273 if err := json.Unmarshal([]byte(cdString), &cd); err != nil {274 t.Fatal(err)275 }276 evCost := engine.EventCost{277 CGRID: cgrID,278 RunID: "*default",279 StartTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),280 Usage: utils.DurationPointer(5 * time.Second),281 Cost: utils.Float64Pointer(0),282 Charges: []*engine.ChargingInterval{{283 RatingID: utils.MetaPause,284 Increments: []*engine.ChargingIncrement{{285 Usage: time.Second,286 Cost: 0,287 AccountingID: utils.MetaPause,288 CompressFactor: 1,289 }},290 CompressFactor: 1,291 }, {292 RatingID: utils.MetaPause,293 Increments: []*engine.ChargingIncrement{{294 Usage: 2 * time.Second,295 Cost: 0,296 AccountingID: utils.MetaPause,297 CompressFactor: 1,298 }},299 CompressFactor: 2,300 }},301 Rating: engine.Rating{302 utils.MetaPause: {303 ConnectFee: 0,304 RoundingMethod: "*up",305 RoundingDecimals: 5,306 MaxCost: 0,307 MaxCostStrategy: "",308 TimingID: "",309 RatesID: utils.MetaPause,310 RatingFiltersID: utils.MetaPause,311 },312 },313 Accounting: engine.Accounting{314 utils.MetaPause: {315 AccountID: "1001",316 BalanceUUID: "",317 RatingID: utils.MetaPause,318 Units: 0,319 ExtraChargeID: "",320 },321 },322 RatingFilters: engine.RatingFilters{323 utils.MetaPause: {324 utils.DestinationID: "",325 utils.DestinationPrefixName: "",326 utils.RatingPlanID: utils.MetaPause,327 utils.Subject: "",328 },329 },330 Rates: engine.ChargedRates{331 utils.MetaPause: {{332 GroupIntervalStart: 0,333 Value: 0,334 RateIncrement: 1,335 RateUnit: 1,336 }},337 },338 Timings: engine.ChargedTimings{339 "": {340 StartTime: "00:00:00",341 },342 },343 }344 // the Timings are not relevant for this test345 for _, r := range cd.Rating {346 r.TimingID = ""347 }348 cd.Timings = evCost.Timings349 if !reflect.DeepEqual(evCost, cd) {350 t.Errorf("Expected %s \n received: %s", utils.ToJSON(evCost), utils.ToJSON(cd))351 }352}353func testSesPauseItInitPause(t *testing.T) {354 cgrID := "1b676c7583ceb27ad7c991ded73b2417faa29a6b"355 testSesPauseItInitSession(t, cgrID, false, time.Second)356 testSesPauseItUpdateSession(t, cgrID, true, 2*time.Second)357 testSesPauseItTerminateSession(t, cgrID, true, 5*time.Second)358 time.Sleep(20 * time.Millisecond)359 var cdrs []*engine.ExternalCDR360 req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}}361 if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil {362 t.Error("Unexpected error: ", err.Error())363 }364 exp := []*engine.ExternalCDR{{365 CGRID: cgrID,366 RunID: "*default",367 OrderID: 0,368 OriginHost: "",369 Source: "",370 OriginID: "TestDebitIterval",371 ToR: "*voice",372 RequestType: "*prepaid",373 Tenant: "cgrates.org",374 Category: "call",375 Account: "1001",376 Subject: "1001",377 Destination: "1002",378 SetupTime: "2018-01-07 17:00:00 +0000 UTC",379 AnswerTime: "2018-01-07 17:00:10 +0000 UTC",380 Usage: "5s",381 ExtraFields: map[string]string{},382 CostSource: "*sessions",383 Cost: 0.2,384 CostDetails: "",385 ExtraInfo: "",386 PreRated: false,387 }}388 if len(cdrs) == 0 {389 t.Fatal("No cdrs returned")390 }391 cdrs[0].OrderID = 0392 cdString := cdrs[0].CostDetails393 cdrs[0].CostDetails = ""394 var val time.Time395 if val, err = utils.ParseTimeDetectLayout(cdrs[0].AnswerTime, ""); err != nil {396 t.Fatal(err)397 }398 cdrs[0].AnswerTime = val.UTC().String()399 if val, err = utils.ParseTimeDetectLayout(cdrs[0].SetupTime, ""); err != nil {400 t.Fatal(err)401 }402 cdrs[0].SetupTime = val.UTC().String()403 if !reflect.DeepEqual(exp, cdrs) {404 t.Errorf("Expected %s \n received: %s", utils.ToJSON(exp), utils.ToJSON(cdrs))405 }406 var cd engine.EventCost407 if err := json.Unmarshal([]byte(cdString), &cd); err != nil {408 t.Fatal(err)409 }410 evCost := engine.EventCost{411 CGRID: cgrID,412 RunID: "*default",413 StartTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),414 Usage: utils.DurationPointer(61 * time.Second),415 Cost: utils.Float64Pointer(0.2),416 Charges: []*engine.ChargingInterval{{417 RatingID: utils.MetaPause,418 Increments: []*engine.ChargingIncrement{{419 Usage: time.Second,420 Cost: 0,421 AccountingID: utils.MetaPause,422 CompressFactor: 1,423 }},424 CompressFactor: 1,425 }, {426 RatingID: "6b4139e",427 Increments: []*engine.ChargingIncrement{{428 Usage: 60 * time.Second,429 Cost: 0.2,430 AccountingID: "8305f9f",431 CompressFactor: 1,432 }},433 CompressFactor: 1,434 }},435 AccountSummary: &engine.AccountSummary{436 Tenant: "cgrates.org",437 ID: "1001",438 BalanceSummaries: engine.BalanceSummaries{{439 UUID: "219cabeb-16cb-446c-837c-8cc74230eecf",440 ID: "test",441 Type: "*monetary",442 Initial: 10,443 Value: 9.8,444 }},445 },446 Rating: engine.Rating{447 utils.MetaPause: {448 ConnectFee: 0,449 RoundingMethod: "*up",450 RoundingDecimals: 5,451 MaxCost: 0,452 MaxCostStrategy: "",453 TimingID: "",454 RatesID: utils.MetaPause,455 RatingFiltersID: utils.MetaPause,456 },457 "6b4139e": {458 ConnectFee: 0.4,459 RoundingMethod: "*up",460 RoundingDecimals: 4,461 MaxCost: 0,462 MaxCostStrategy: "",463 TimingID: "",464 RatesID: "3d3179b",465 RatingFiltersID: "00eaefb",466 },467 },468 Accounting: engine.Accounting{469 utils.MetaPause: {470 AccountID: "1001",471 BalanceUUID: "",472 RatingID: utils.MetaPause,473 Units: 0,474 ExtraChargeID: "",475 },476 "8305f9f": {477 AccountID: "cgrates.org:1001",478 BalanceUUID: "219cabeb-16cb-446c-837c-8cc74230eecf",479 RatingID: "",480 Units: 0.2,481 ExtraChargeID: "",482 },483 },484 RatingFilters: engine.RatingFilters{485 utils.MetaPause: {486 utils.DestinationID: "",487 utils.DestinationPrefixName: "",488 utils.RatingPlanID: utils.MetaPause,489 utils.Subject: "",490 },491 "00eaefb": {492 utils.DestinationID: "DST_1002",493 utils.DestinationPrefixName: "1002",494 utils.RatingPlanID: "RP_1001",495 utils.Subject: "*out:cgrates.org:call:1001",496 },497 },498 Rates: engine.ChargedRates{499 utils.MetaPause: {{500 GroupIntervalStart: 0,501 Value: 0,502 RateIncrement: 1,503 RateUnit: 1,504 }},505 "3d3179b": {{506 GroupIntervalStart: 0,507 Value: 0.2,508 RateIncrement: 60 * time.Second,509 RateUnit: 60 * time.Second,510 }, {511 GroupIntervalStart: 60 * time.Second,512 Value: 0.1,513 RateIncrement: time.Second,514 RateUnit: 60 * time.Second,515 }},516 },517 Timings: engine.ChargedTimings{518 "": {519 StartTime: "00:00:00",520 },521 },522 }523 // we already tested that the keys are populated corectly524 // sync the curent keys to better compare525 cd.AccountSummary.BalanceSummaries[0].UUID = evCost.AccountSummary.BalanceSummaries[0].UUID526 for k, ac := range cd.Accounting {527 if k != utils.MetaPause {528 ac.BalanceUUID = evCost.AccountSummary.BalanceSummaries[0].UUID529 }530 }531 cd.SyncKeys(&evCost)532 if !reflect.DeepEqual(evCost, cd) {533 t.Errorf("Expected %s \n received: %s", utils.ToJSON(evCost), utils.ToJSON(cd))534 }535}536func testSesPauseItInitUpdatePause(t *testing.T) {537 cgrID := "1b676c7583ceb27ad7c991ded73b2417faa29a6c"538 testSesPauseItInitSession(t, cgrID, false, time.Second)539 testSesPauseItUpdateSession(t, cgrID, false, 2*time.Second)540 testSesPauseItTerminateSession(t, cgrID, true, 5*time.Second)541 time.Sleep(20 * time.Millisecond)542 var cdrs []*engine.ExternalCDR543 req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}}544 if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil {545 t.Error("Unexpected error: ", err.Error())546 }547 exp := []*engine.ExternalCDR{{548 CGRID: cgrID,549 RunID: "*default",550 OrderID: 0,551 OriginHost: "",552 Source: "",553 OriginID: "TestDebitIterval",554 ToR: "*voice",555 RequestType: "*prepaid",556 Tenant: "cgrates.org",557 Category: "call",558 Account: "1001",559 Subject: "1001",560 Destination: "1002",561 SetupTime: "2018-01-07 17:00:00 +0000 UTC",562 AnswerTime: "2018-01-07 17:00:10 +0000 UTC",563 Usage: "5s",564 ExtraFields: map[string]string{},565 CostSource: "*sessions",566 Cost: 0.2,567 CostDetails: "",568 ExtraInfo: "",569 PreRated: false,570 }}571 if len(cdrs) == 0 {572 t.Fatal("No cdrs returned")573 }574 cdrs[0].OrderID = 0575 cdString := cdrs[0].CostDetails576 cdrs[0].CostDetails = ""577 var val time.Time578 if val, err = utils.ParseTimeDetectLayout(cdrs[0].AnswerTime, ""); err != nil {579 t.Fatal(err)580 }581 cdrs[0].AnswerTime = val.UTC().String()582 if val, err = utils.ParseTimeDetectLayout(cdrs[0].SetupTime, ""); err != nil {583 t.Fatal(err)584 }585 cdrs[0].SetupTime = val.UTC().String()586 if !reflect.DeepEqual(exp, cdrs) {587 t.Errorf("Expected %s \n received: %s", utils.ToJSON(exp), utils.ToJSON(cdrs))588 }589 var cd engine.EventCost590 if err := json.Unmarshal([]byte(cdString), &cd); err != nil {591 t.Fatal(err)592 }593 evCost := engine.EventCost{594 CGRID: cgrID,595 RunID: "*default",596 StartTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),597 Usage: utils.DurationPointer(63 * time.Second),598 Cost: utils.Float64Pointer(0.2),599 Charges: []*engine.ChargingInterval{{600 RatingID: utils.MetaPause,601 Increments: []*engine.ChargingIncrement{{602 Usage: time.Second,603 Cost: 0,604 AccountingID: utils.MetaPause,605 CompressFactor: 1,606 }},607 CompressFactor: 1,608 }, {609 RatingID: utils.MetaPause,610 Increments: []*engine.ChargingIncrement{{611 Usage: 2 * time.Second,612 Cost: 0,613 AccountingID: utils.MetaPause,614 CompressFactor: 1,615 }},616 CompressFactor: 1,617 }, {618 RatingID: "6b4139e",619 Increments: []*engine.ChargingIncrement{{620 Usage: 60 * time.Second,621 Cost: 0.2,622 AccountingID: "8305f9f",623 CompressFactor: 1,624 }},625 CompressFactor: 1,626 }},627 AccountSummary: &engine.AccountSummary{628 Tenant: "cgrates.org",629 ID: "1001",630 BalanceSummaries: engine.BalanceSummaries{{631 UUID: "219cabeb-16cb-446c-837c-8cc74230eecf",632 ID: "test",633 Type: "*monetary",634 Initial: 9.8,635 Value: 9.6,636 }},637 },638 Rating: engine.Rating{639 utils.MetaPause: {640 ConnectFee: 0,641 RoundingMethod: "*up",642 RoundingDecimals: 5,643 MaxCost: 0,644 MaxCostStrategy: "",645 TimingID: "",646 RatesID: utils.MetaPause,647 RatingFiltersID: utils.MetaPause,648 },649 "6b4139e": {650 ConnectFee: 0.4,651 RoundingMethod: "*up",652 RoundingDecimals: 4,653 MaxCost: 0,654 MaxCostStrategy: "",655 TimingID: "",656 RatesID: "3d3179b",657 RatingFiltersID: "00eaefb",658 },659 },660 Accounting: engine.Accounting{661 utils.MetaPause: {662 AccountID: "1001",663 BalanceUUID: "",664 RatingID: utils.MetaPause,665 Units: 0,666 ExtraChargeID: "",667 },668 "8305f9f": {669 AccountID: "cgrates.org:1001",670 BalanceUUID: "219cabeb-16cb-446c-837c-8cc74230eecf",671 RatingID: "",672 Units: 0.2,673 ExtraChargeID: "",674 },675 },676 RatingFilters: engine.RatingFilters{677 utils.MetaPause: {678 utils.DestinationID: "",679 utils.DestinationPrefixName: "",680 utils.RatingPlanID: utils.MetaPause,681 utils.Subject: "",682 },683 "00eaefb": {684 utils.DestinationID: "DST_1002",685 utils.DestinationPrefixName: "1002",686 utils.RatingPlanID: "RP_1001",687 utils.Subject: "*out:cgrates.org:call:1001",688 },689 },690 Rates: engine.ChargedRates{691 utils.MetaPause: {{692 GroupIntervalStart: 0,693 Value: 0,694 RateIncrement: 1,695 RateUnit: 1,696 }},697 "3d3179b": {{698 GroupIntervalStart: 0,699 Value: 0.2,700 RateIncrement: 60 * time.Second,701 RateUnit: 60 * time.Second,702 }, {703 GroupIntervalStart: 60 * time.Second,704 Value: 0.1,705 RateIncrement: time.Second,706 RateUnit: 60 * time.Second,707 }},708 },709 Timings: engine.ChargedTimings{710 "": {711 StartTime: "00:00:00",712 },713 },714 }715 // we already tested that the keys are populated corectly716 // sync the curent keys to better compare717 cd.AccountSummary.BalanceSummaries[0].UUID = evCost.AccountSummary.BalanceSummaries[0].UUID718 for k, ac := range cd.Accounting {719 if k != utils.MetaPause {720 ac.BalanceUUID = evCost.AccountSummary.BalanceSummaries[0].UUID721 }722 }723 cd.SyncKeys(&evCost)724 if !reflect.DeepEqual(evCost, cd) {725 t.Errorf("Expected %s \n received: %s", utils.ToJSON(evCost), utils.ToJSON(cd))726 }727}728func testSesPauseItUpdatePause(t *testing.T) {729 cgrID := "1b676c7583ceb27ad7c991ded73b2417faa29a6d"730 testSesPauseItInitSession(t, cgrID, true, 30*time.Second) // debit 60s( the ratre interval is 60s)731 testSesPauseItUpdateSession(t, cgrID, false, 10*time.Second) // have a pause of 10s732 testSesPauseItUpdateSession(t, cgrID, true, 40*time.Second) // debit the 430s left from previsos debit and 10s extra733 testSesPauseItTerminateSession(t, cgrID, true, 65*time.Second) // end call with less than 80s and refund 10s734 time.Sleep(20 * time.Millisecond)735 var cdrs []*engine.ExternalCDR736 req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}}737 if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil {738 t.Error("Unexpected error: ", err.Error())739 }740 exp := []*engine.ExternalCDR{{741 CGRID: cgrID,742 RunID: "*default",743 OrderID: 0,744 OriginHost: "",745 Source: "",746 OriginID: "TestDebitIterval",747 ToR: "*voice",748 RequestType: "*prepaid",749 Tenant: "cgrates.org",750 Category: "call",751 Account: "1001",752 Subject: "1001",753 Destination: "1002",754 SetupTime: "2018-01-07 17:00:00 +0000 UTC",755 AnswerTime: "2018-01-07 17:00:10 +0000 UTC",756 Usage: "1m5s",757 ExtraFields: map[string]string{},758 CostSource: "*sessions",759 Cost: 0.6,760 CostDetails: "",761 ExtraInfo: "",762 PreRated: false,763 }}764 if len(cdrs) == 0 {765 t.Fatal("No cdrs returned")766 }767 cdrs[0].OrderID = 0768 cdString := cdrs[0].CostDetails769 cdrs[0].CostDetails = ""770 var val time.Time771 if val, err = utils.ParseTimeDetectLayout(cdrs[0].AnswerTime, ""); err != nil {772 t.Fatal(err)773 }774 cdrs[0].AnswerTime = val.UTC().String()775 if val, err = utils.ParseTimeDetectLayout(cdrs[0].SetupTime, ""); err != nil {776 t.Fatal(err)777 }778 cdrs[0].SetupTime = val.UTC().String()779 if !reflect.DeepEqual(exp, cdrs) {780 t.Errorf("Expected %s \n received: %s", utils.ToJSON(exp), utils.ToJSON(cdrs))781 }782 var cd engine.EventCost783 if err := json.Unmarshal([]byte(cdString), &cd); err != nil {784 t.Fatal(err)785 }786 evCost := engine.EventCost{787 CGRID: cgrID,788 RunID: "*default",789 StartTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),790 Usage: utils.DurationPointer(70 * time.Second),791 Cost: utils.Float64Pointer(0.6),792 Charges: []*engine.ChargingInterval{793 {794 RatingID: "6b4139e",795 Increments: []*engine.ChargingIncrement{796 {797 Usage: 0,798 Cost: 0.4,799 AccountingID: "f2137e2",800 CompressFactor: 1,801 },802 {803 Usage: 60000000000,804 Cost: 0.2,805 AccountingID: "8305f9f",806 CompressFactor: 1,807 }},808 CompressFactor: 1,809 },810 {811 RatingID: "*pause",812 Increments: []*engine.ChargingIncrement{{813 Usage: 10000000000,814 Cost: 0,815 AccountingID: "*pause",816 CompressFactor: 1,817 }},818 CompressFactor: 1,819 },820 },821 AccountSummary: &engine.AccountSummary{822 Tenant: "cgrates.org",823 ID: "1001",824 BalanceSummaries: engine.BalanceSummaries{{825 UUID: "219cabeb-16cb-446c-837c-8cc74230eecf",826 ID: "test",827 Type: "*monetary",828 Initial: 9.6,829 Value: 9.,830 }},831 },832 Rating: engine.Rating{833 utils.MetaPause: {834 ConnectFee: 0,835 RoundingMethod: "*up",836 RoundingDecimals: 5,837 MaxCost: 0,838 MaxCostStrategy: "",839 TimingID: "",840 RatesID: utils.MetaPause,841 RatingFiltersID: utils.MetaPause,842 },843 "6b4139e": {844 ConnectFee: 0.4,845 RoundingMethod: "*up",846 RoundingDecimals: 4,847 MaxCost: 0,848 MaxCostStrategy: "",849 TimingID: "",850 RatesID: "3d3179b",851 RatingFiltersID: "00eaefb",852 },853 },854 Accounting: engine.Accounting{855 utils.MetaPause: {856 AccountID: "1001",857 BalanceUUID: "",858 RatingID: utils.MetaPause,859 Units: 0,860 ExtraChargeID: "",861 },862 "8305f9f": {863 AccountID: "cgrates.org:1001",864 BalanceUUID: "219cabeb-16cb-446c-837c-8cc74230eecf",865 RatingID: "",866 Units: 0.2,867 ExtraChargeID: "",868 },869 "f2137e2": {870 AccountID: "cgrates.org:1001",871 BalanceUUID: "219cabeb-16cb-446c-837c-8cc74230eecf",872 RatingID: "",873 Units: 0.4,874 },875 },876 RatingFilters: engine.RatingFilters{877 utils.MetaPause: {878 utils.DestinationID: "",879 utils.DestinationPrefixName: "",880 utils.RatingPlanID: utils.MetaPause,881 utils.Subject: "",882 },883 "00eaefb": {884 utils.DestinationID: "DST_1002",885 utils.DestinationPrefixName: "1002",886 utils.RatingPlanID: "RP_1001",887 utils.Subject: "*out:cgrates.org:call:1001",888 },889 },890 Rates: engine.ChargedRates{891 utils.MetaPause: {{892 GroupIntervalStart: 0,893 Value: 0,894 RateIncrement: 1,895 RateUnit: 1,896 }},897 "3d3179b": {{898 GroupIntervalStart: 0,899 Value: 0.2,900 RateIncrement: 60 * time.Second,901 RateUnit: 60 * time.Second,902 }, {903 GroupIntervalStart: 60 * time.Second,904 Value: 0.1,905 RateIncrement: time.Second,906 RateUnit: 60 * time.Second,907 }},908 },909 Timings: engine.ChargedTimings{910 "": {911 Years: utils.Years{},912 Months: utils.Months{},913 MonthDays: utils.MonthDays{},914 WeekDays: utils.WeekDays{},915 StartTime: "00:00:00",916 },917 },918 }919 // we already tested that the keys are populated corectly920 // sync the curent keys to better compare921 cd.AccountSummary.BalanceSummaries[0].UUID = evCost.AccountSummary.BalanceSummaries[0].UUID922 for k, ac := range cd.Accounting {923 if k != utils.MetaPause {924 ac.BalanceUUID = evCost.AccountSummary.BalanceSummaries[0].UUID925 }926 }927 cd.SyncKeys(&evCost)928 if !reflect.DeepEqual(evCost, cd) {929 t.Errorf("Expected %s \n received: %s", utils.ToJSON(evCost), utils.ToJSON(cd))930 }931}932func testSesPauseItStopCgrEngine(t *testing.T) {933 if err := engine.KillEngine(100); err != nil {934 t.Error(err)935 }936}...

Full Screen

Full Screen

timing.go

Source:timing.go Github

copy

Full Screen

...236 }237 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_RESTART)238 utils.APIOK(ctx)239}240func (c *TimingController) Pause(ctx *gin.Context) {241 timing := utils.GetTiming(ctx)242 agent := utils.GetAgent(ctx)243 client, err := providers.GetAgent(agent)244 if err != nil {245 utils.APIError(ctx, "初始化RPC客户端异常:\n"+err.Error())246 return247 }248 _timing, err := client.GetTiming(timing.ID)249 if err != nil {250 utils.APIError(ctx, fmt.Sprintf("获取定时任务情况异常:%s", err.Error()))251 return252 }253 if _timing != nil {254 err = client.RemoveTiming(timing.ID)255 if err != nil {256 utils.APIError(ctx, fmt.Sprintf("停止定时任务异常:%s", err.Error()))257 return258 }259 }260 ok := providers.TimingService.ChangeTimingStatus(timing, constants.TIMING_STATUS_PAUSE, utils.GetUserID(ctx))261 if !ok {262 utils.APIError(ctx, "更新定时任务状态失败")263 return264 }265 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_PAUSE)266 utils.APIOK(ctx)267}268func (c *TimingController) Delete(ctx *gin.Context) {269 timing := utils.GetTiming(ctx)270 agent := utils.GetAgent(ctx)271 if timing.Status != constants.TIMING_STATUS_PAUSE {272 utils.APIError(ctx, "定时任务启动状态不能删除")273 return274 }275 client, err := providers.GetAgent(agent)276 if err != nil {277 utils.APIError(ctx, "初始化RPC客户端异常:\n"+err.Error())278 return279 }280 _timing, err := client.GetTiming(timing.ID)281 if err != nil {282 utils.APIError(ctx, fmt.Sprintf("获取定时任务情况异常:%s", err.Error()))283 return284 }285 if _timing != nil {286 err = client.RemoveTiming(timing.ID)287 if err != nil {288 utils.APIError(ctx, fmt.Sprintf("停止定时任务异常:%s", err.Error()))289 return290 }291 }292 ok := providers.TimingService.ChangeTimingStatus(timing, constants.TIMING_STATUS_DELETED, utils.GetUserID(ctx))293 if !ok {294 utils.APIError(ctx, "更新定时任务状态失败")295 return296 }297 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_DELETE)298 utils.APIOK(ctx)299}300func (c *TimingController) BatchStart(ctx *gin.Context) {301 timingAgent := utils.GetTimingAgent(ctx)302 for timing, agent := range timingAgent {303 if timing.Status == constants.TIMING_STATUS_RUNNING {304 continue305 }306 client, err := providers.GetAgent(agent)307 if err != nil {308 logger.Errorf("Timing BatchStart GetAgent Error:[%d][%s]", timing.ID, err.Error())309 continue310 }311 _timing, err := client.GetTiming(timing.ID)312 if err != nil {313 logger.Errorf("Timing BatchStart GetAgentTiming Error:[%d][%s]", timing.ID, err.Error())314 continue315 }316 if _timing == nil {317 err = client.AddTiming(timing)318 if err != nil {319 logger.Errorf("Timing BatchStart AddAgentTiming Error:%s", err.Error())320 }321 }322 providers.TimingService.ChangeTimingStatus(timing, constants.TIMING_STATUS_RUNNING, utils.GetUserID(ctx))323 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_START)324 }325 utils.APIOK(ctx)326}327func (c *TimingController) BatchReStart(ctx *gin.Context) {328 timingAgent := utils.GetTimingAgent(ctx)329 for timing, agent := range timingAgent {330 client, err := providers.GetAgent(agent)331 if err != nil {332 logger.Errorf("Timing BatchReStart GetAgent Error:[%d][%s]", timing.ID, err.Error())333 continue334 }335 _timing, err := client.GetTiming(timing.ID)336 if err != nil {337 logger.Errorf("Timing BatchReStart GetAgentTiming Error:[%d][%s]", timing.ID, err.Error())338 continue339 }340 if _timing == nil {341 err = client.AddTiming(timing)342 if err != nil {343 logger.Errorf("Timing BatchReStart AddAgentTiming Error:[%d][%s]", timing.ID, err.Error())344 }345 } else {346 err = client.UpdateTiming(timing)347 if err != nil {348 logger.Errorf("Timing BatchReStart UpdateAgentJob Error:[%d][%s]", timing.ID, err.Error())349 }350 }351 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_RESTART)352 }353 utils.APIOK(ctx)354}355func (c *TimingController) BatchPause(ctx *gin.Context) {356 timingAgent := utils.GetTimingAgent(ctx)357 for timing, agent := range timingAgent {358 client, err := providers.GetAgent(agent)359 if err != nil {360 logger.Errorf("Timing BatchPause GetAgent Error:[%d][%s]", timing.ID, err.Error())361 }362 _timing, err := client.GetTiming(timing.ID)363 if err != nil {364 logger.Errorf("Timing BatchPause GetAgentTiming Error:[%d][%s]", timing.ID, err.Error())365 continue366 }367 if _timing != nil {368 err = client.RemoveTiming(timing.ID)369 if err != nil {370 logger.Errorf("Timing BatchPause RemoveAgentTiming Error:[%d][%s]", timing.ID, err.Error())371 return372 }373 }374 providers.TimingService.ChangeTimingStatus(timing, constants.TIMING_STATUS_PAUSE, utils.GetUserID(ctx))375 utils.OpetationLog(utils.GetUserID(ctx), constants.TYPE_TIMING, timing.ID, constants.ACTION_PAUSE)376 }377 utils.APIOK(ctx)378}379func (c *TimingController) BatchDelete(ctx *gin.Context) {380 timingAgent := utils.GetTimingAgent(ctx)381 for timing, agent := range timingAgent {382 if timing.Status == constants.TIMING_STATUS_RUNNING {383 continue384 }...

Full Screen

Full Screen

pauseApp.go

Source:pauseApp.go Github

copy

Full Screen

1package app2import (3 "github.com/baidu/smartapp-openapi-go/utils"4)5// PauseAppRequest 请求结构体6type PauseAppRequest struct {7 AccessToken string // 授权小程序的接口调用凭据8}9// 响应结构体10type PauseAppResponse struct {11 Errno int64 `json:"errno"` // 状态码12 ErrMsg string `json:"msg"` // 错误信息13 ErrorCode int64 `json:"error_code"` // openapi 错误码14 ErrorMsg string `json:"error_msg"` // openapi 错误信息15 Data PauseAppResponsedata16}17type PauseAppResponsedata struct {18 Errno int64 `json:"errno"` // 状态码19 Msg string `json:"msg"` // 状态描述20}21// PauseApp22func PauseApp(params *PauseAppRequest) (*PauseAppResponsedata, error) {23 var (24 err error25 defaultRet *PauseAppResponsedata26 )27 respData := &PauseAppResponse{}28 client := utils.NewHTTPClient().29 SetContentType(utils.ContentTypeForm).30 SetConverterType(utils.ConverterTypeJSON).31 SetMethod("POST").32 SetScheme(utils.SCHEME).33 SetHost(utils.OPENAPIHOST).34 SetPath("/rest/2.0/smartapp/app/pause")35 client.AddGetParam("access_token", params.AccessToken)36 client.AddGetParam("sp_sdk_ver", utils.SDKVERSION)37 client.AddGetParam("sp_sdk_lang", utils.SDKLANG)38 err = client.Do()39 if err != nil {40 return defaultRet, err41 }...

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 utils.Pause()5}6import (7func Pause() {8 fmt.Println("Press 'Enter' to continue...")9 bufio.NewReader(os.Stdin).ReadBytes('\n')10}

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting...")4 utils.Pause(2 * time.Second)5 fmt.Println("Ending...")6}7import "time"8func Pause(duration time.Duration) {9 time.Sleep(duration)10}11import (12func TestPause(t *testing.T) {13 start := time.Now()14 Pause(2 * time.Second)15 duration := time.Since(start)16 if duration < 2*time.Second {17 t.Error("Pause returned too early")18 }19}20import "testing"21func BenchmarkPause(b *testing.B) {22 for i := 0; i < b.N; i++ {23 Pause(1 * time.Second)24 }25}26import "fmt"27func ExamplePause() {28 fmt.Println("Starting...")29 Pause(2 * time.Second)30 fmt.Println("Ending...")31}32import (33func TestPause(t *testing.T) {34 start := time.Now()35 Pause(2 * time.Second)36 duration := time.Since(start)37 if duration < 2*time.Second {38 t.Error("Pause returned too early")39 }40}41import "testing"42func BenchmarkPause(b *testing.B) {43 for i := 0; i < b.N; i++ {44 Pause(1 * time.Second)45 }46}47import "fmt"48func ExamplePause() {49 fmt.Println("Starting...")50 Pause(2 * time.Second)51 fmt.Println("Ending...")52}53import (54func TestPause(t *testing.T) {55 start := time.Now()56 Pause(2 * time.Second)57 duration := time.Since(start

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 utils.Pause(time.Second)5 fmt.Println("Bye World")6}7import (8func Pause(duration time.Duration) {9 time.Sleep(duration)10}

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 golutils.Pause()5}6import (7func main() {8 fmt.Println("Hello, playground")9 golutils.Pause()10}

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mc := memcache.New("localhost:11211")4 mc.Set(&memcache.Item{Key: "foo", Value: []byte("bar")})5 item, err := mc.Get("foo")6 if err != nil {7 panic(err)8 }9 fmt.Printf("%s\n", item.Value)10 if err := memcachetool.Pause(mc, 10*time.Second); err != nil {11 panic(err)12 }13 item, err = mc.Get("foo")14 if err != nil {15 fmt.Println(err)16 }17}18import (19func main() {20 mc := memcache.New("localhost:11211")21 mc.Set(&memcache.Item{Key: "foo", Value: []byte("bar")})22 item, err := mc.Get("foo")23 if err != nil {24 panic(err)25 }26 fmt.Printf("%s\n", item.Value)27 if err := memcachetool.Pause(mc, 10*time.Second); err != nil {28 panic(err)29 }30 item, err = mc.Get("foo")31 if err != nil {32 fmt.Println(err)33 }34 if err := memcachetool.Resume(mc); err != nil {35 panic(err)36 }37 item, err = mc.Get("foo")38 if err != nil {39 panic(err)40 }41 fmt.Printf("%s\n", item.Value)42}

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 utils.Pause()5}6import (7func Pause() {8 fmt.Println("Press 'Enter' to continue...")9 bufio.NewReader(os.Stdin).ReadBytes('\n')10}11time.Sleep(time.Second * 5)12func main() {13 ticker := time.Tick(time.Second * 5)14 for {15 select {16 fmt.Println("Hello, playground")17 }18 }19}20func main() {21 time.After(time.Second * 5)22 fmt.Println("Hello, playground")23}24func main()

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 utils.Pause()5}6import (7func main() {8 fmt.Println("Hello, playground")9 utils.Pause()10}11import (12func main() {13 fmt.Println("Hello, playground")14 utils.Pause()15}16import (17func main() {18 fmt.Println("Hello, playground")19 utils.Pause()20}21import (22func main() {23 fmt.Println("Hello, playground")24 utils.Pause()25}26import (27func main() {28 fmt.Println("Hello, playground")29 utils.Pause()30}31import (32func main() {33 fmt.Println("Hello, playground")34 utils.Pause()35}36import (37func main() {38 fmt.Println("Hello, playground")39 utils.Pause()40}41import (42func main() {43 fmt.Println("Hello, playground")44 utils.Pause()45}46import (47func main() {48 fmt.Println("Hello, playground")

Full Screen

Full Screen

Pause

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("GoLangUtils - Pause")4 utils.Pause()5}6import (7func main() {8 fmt.Println("GoLangUtils - Restart")9 utils.Restart()10}11import (12func main() {13 fmt.Println("GoLangUtils - ClearScreen")14 utils.ClearScreen()15}16import (17func main() {18 fmt.Println("GoLangUtils - ClearLine")19 utils.ClearLine()20}21import (22func main() {23 fmt.Println("GoLangUtils - ClearLines")24 utils.ClearLines(10)25}26import (27func main() {28 fmt.Println("GoLangUtils - ClearLinesFrom")29 utils.ClearLinesFrom(10)30}31import (32func main() {33 fmt.Println("GoLangUtils - ClearLinesTo")34 utils.ClearLinesTo(10)35}36import (37func main() {38 fmt.Println("GoLangUtils - ClearLinesBetween")39 utils.ClearLinesBetween(10, 20)40}41import (42func main() {43 fmt.Println("GoLangUtils - ClearLinesBetweenWithOffset")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful