From de38e16afe4de18de28a550e0b73dd1b7048a1e0 Mon Sep 17 00:00:00 2001 From: adragusin Date: Wed, 22 Jan 2020 14:25:52 +0200 Subject: [PATCH] Updated IT tests in sessions --- .../cgrates.json | 54 ++++++++++++ .../smg_automatic_debits_mongo/cgrates.json | 59 +++++++++++++ .../cgrates.json | 6 ++ data/conf/samples/smg_internal/cgrates.json | 77 ++++++++++++++++ .../samples/smg_internal_gob/cgrates.json | 84 ++++++++++++++++++ data/conf/samples/smg_mongo/cgrates.json | 81 +++++++++++++++++ data/conf/samples/smg_mongo_gob/cgrates.json | 88 +++++++++++++++++++ .../samples/{smg => smg_mysql}/cgrates.json | 6 ++ .../{smg_gob => smg_mysql_gob}/cgrates.json | 6 ++ .../samples/smgreplcmaster_mongo/cgrates.json | 71 +++++++++++++++ .../smgreplcmaster_mongo_gob/cgrates.json | 71 +++++++++++++++ .../cgrates.json | 0 .../cgrates.json | 0 .../samples/smgreplcslave_mongo/cgrates.json | 76 ++++++++++++++++ .../smgreplcslave_mongo_gob/cgrates.json | 75 ++++++++++++++++ .../cgrates.json | 0 .../cgrates.json | 0 integration_test.sh | 25 ++++-- migrator/accounts_it_test.go | 12 +-- sessions/lib_test.go | 47 ++++++++++ sessions/sessions_birpc_it_test.go | 51 ++++++++--- sessions/sessions_data_it_test.go | 78 +++++++++++----- sessions/sessions_it_test.go | 71 +++++++++++---- sessions/sessions_rpl_it_test.go | 77 +++++++++++----- sessions/sessions_voice_it_test.go | 88 ++++++++++++------- 25 files changed, 1086 insertions(+), 117 deletions(-) create mode 100644 data/conf/samples/smg_automatic_debits_internal/cgrates.json create mode 100644 data/conf/samples/smg_automatic_debits_mongo/cgrates.json rename data/conf/samples/{smg_automatic_debits => smg_automatic_debits_mysql}/cgrates.json (89%) create mode 100644 data/conf/samples/smg_internal/cgrates.json create mode 100644 data/conf/samples/smg_internal_gob/cgrates.json create mode 100644 data/conf/samples/smg_mongo/cgrates.json create mode 100644 data/conf/samples/smg_mongo_gob/cgrates.json rename data/conf/samples/{smg => smg_mysql}/cgrates.json (92%) rename data/conf/samples/{smg_gob => smg_mysql_gob}/cgrates.json (93%) create mode 100644 data/conf/samples/smgreplcmaster_mongo/cgrates.json create mode 100644 data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json rename data/conf/samples/{smgreplcmaster => smgreplcmaster_mysql}/cgrates.json (100%) rename data/conf/samples/{smgreplcmaster_gob => smgreplcmaster_mysql_gob}/cgrates.json (100%) create mode 100644 data/conf/samples/smgreplcslave_mongo/cgrates.json create mode 100644 data/conf/samples/smgreplcslave_mongo_gob/cgrates.json rename data/conf/samples/{smgreplcslave => smgreplcslave_mysql}/cgrates.json (100%) rename data/conf/samples/{smgreplcslave_gob => smgreplcslave_mysql_gob}/cgrates.json (100%) create mode 100644 sessions/lib_test.go diff --git a/data/conf/samples/smg_automatic_debits_internal/cgrates.json b/data/conf/samples/smg_automatic_debits_internal/cgrates.json new file mode 100644 index 000000000..fce978556 --- /dev/null +++ b/data/conf/samples/smg_automatic_debits_internal/cgrates.json @@ -0,0 +1,54 @@ +{ +// CGRateS Configuration file +// +// Used in tests + +"general": { + "log_level": 7, +}, + +"data_db": { + "db_type": "*internal", +}, + + +"stor_db": { + "db_type": "*internal", +}, + +"rals": { + "enabled": true, // enable Rater service: +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"attributes": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "debit_interval": "1ms", // interval to perform debits on. + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg_automatic_debits_mongo/cgrates.json b/data/conf/samples/smg_automatic_debits_mongo/cgrates.json new file mode 100644 index 000000000..30d2f543d --- /dev/null +++ b/data/conf/samples/smg_automatic_debits_mongo/cgrates.json @@ -0,0 +1,59 @@ +{ +// CGRateS Configuration file +// +// Used in tests + +"general": { + "log_level": 7, +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, // enable Rater service: +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"attributes": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "debit_interval": "1ms", // interval to perform debits on. + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg_automatic_debits/cgrates.json b/data/conf/samples/smg_automatic_debits_mysql/cgrates.json similarity index 89% rename from data/conf/samples/smg_automatic_debits/cgrates.json rename to data/conf/samples/smg_automatic_debits_mysql/cgrates.json index d3d5b5ad9..4fd47f133 100644 --- a/data/conf/samples/smg_automatic_debits/cgrates.json +++ b/data/conf/samples/smg_automatic_debits_mysql/cgrates.json @@ -7,6 +7,12 @@ "log_level": 7, }, +"data_db": { + "db_type": "redis", + "db_port": 6379, + "db_name": "10", +}, + "stor_db": { // database used to store offline tariff plans and CDRs "db_password": "CGRateS.org", // password to use when connecting to stordb }, diff --git a/data/conf/samples/smg_internal/cgrates.json b/data/conf/samples/smg_internal/cgrates.json new file mode 100644 index 000000000..1d48b7f36 --- /dev/null +++ b/data/conf/samples/smg_internal/cgrates.json @@ -0,0 +1,77 @@ +{ +// CGRateS Configuration file +// +// Used for cgradmin +// Starts rater, scheduler + +"general": { + "log_level": 7, +}, + +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + +"data_db": { + "db_type": "*internal", +}, + + +"stor_db": { + "db_type": "*internal", +}, + +"rals": { + "enabled": true, // enable Rater service: + "max_computed_usage": { // do not compute usage higher than this, prevents memory overload + "*any": "189h", + "*voice": "72h", + "*data": "102400", + "*sms": "10000" + }, +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"resources": { + "enabled": true, + "store_interval": "-1", +}, + +"attributes": { + "enabled": true, +}, + +"suppliers": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "session_ttl": "50ms", + "rals_conns": ["*localhost"], + "cdrs_conns": ["*localhost"], + "chargers_conns": ["*internal"], + "alterable_fields": ["Extra1"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg_internal_gob/cgrates.json b/data/conf/samples/smg_internal_gob/cgrates.json new file mode 100644 index 000000000..6e99095b8 --- /dev/null +++ b/data/conf/samples/smg_internal_gob/cgrates.json @@ -0,0 +1,84 @@ +{ +// CGRateS Configuration file +// +// Used for cgradmin +// Starts rater, scheduler + +"general": { + "log_level": 7, +}, + +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + +"rpc_conns": { + "conn1": { + "strategy": "*first", + "conns": [{"address": "127.0.0.1:2013", "transport":"*gob"}], + }, +}, + +"data_db": { + "db_type": "*internal", +}, + + +"stor_db": { + "db_type": "*internal", +}, + +"rals": { + "enabled": true, // enable Rater service: + "max_computed_usage": { // do not compute usage higher than this, prevents memory overload + "*any": "189h", + "*voice": "72h", + "*data": "102400", + "*sms": "10000" + }, +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"resources": { + "enabled": true, + "store_interval": "-1", +}, + +"attributes": { + "enabled": true, +}, + +"suppliers": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "session_ttl": "50ms", + "rals_conns": ["conn1"], + "cdrs_conns": ["conn1"], + "chargers_conns": ["*internal"], + "alterable_fields": ["Extra1"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg_mongo/cgrates.json b/data/conf/samples/smg_mongo/cgrates.json new file mode 100644 index 000000000..006cb7a9e --- /dev/null +++ b/data/conf/samples/smg_mongo/cgrates.json @@ -0,0 +1,81 @@ +{ +// CGRateS Configuration file +// +// Used for cgradmin +// Starts rater, scheduler + +"general": { + "log_level": 7, +}, + +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, // enable Rater service: + "max_computed_usage": { // do not compute usage higher than this, prevents memory overload + "*any": "189h", + "*voice": "72h", + "*data": "102400", + "*sms": "10000" + }, +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"resources": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + +"suppliers": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "session_ttl": "50ms", + "rals_conns": ["*localhost"], + "cdrs_conns": ["*localhost"], + "chargers_conns": ["*internal"], + "alterable_fields": ["Extra1"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg_mongo_gob/cgrates.json b/data/conf/samples/smg_mongo_gob/cgrates.json new file mode 100644 index 000000000..002c1b22d --- /dev/null +++ b/data/conf/samples/smg_mongo_gob/cgrates.json @@ -0,0 +1,88 @@ +{ +// CGRateS Configuration file +// +// Used for cgradmin +// Starts rater, scheduler + +"general": { + "log_level": 7, +}, + +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + +"rpc_conns": { + "conn1": { + "strategy": "*first", + "conns": [{"address": "127.0.0.1:2013", "transport":"*gob"}], + }, +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, // enable Rater service: + "max_computed_usage": { // do not compute usage higher than this, prevents memory overload + "*any": "189h", + "*voice": "72h", + "*data": "102400", + "*sms": "10000" + }, +}, + +"schedulers": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"resources": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + +"suppliers": { + "enabled": true, +}, + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "session_ttl": "50ms", + "rals_conns": ["conn1"], + "cdrs_conns": ["conn1"], + "chargers_conns": ["*internal"], + "alterable_fields": ["Extra1"], +}, + + +"apier": { + "scheduler_conns": ["*internal"], +}, + + +} diff --git a/data/conf/samples/smg/cgrates.json b/data/conf/samples/smg_mysql/cgrates.json similarity index 92% rename from data/conf/samples/smg/cgrates.json rename to data/conf/samples/smg_mysql/cgrates.json index 8fd88f43b..7116cf87b 100644 --- a/data/conf/samples/smg/cgrates.json +++ b/data/conf/samples/smg_mysql/cgrates.json @@ -14,6 +14,12 @@ "http": ":2080", // HTTP listening address }, +"data_db": { + "db_type": "redis", + "db_port": 6379, + "db_name": "10", +}, + "stor_db": { // database used to store offline tariff plans and CDRs "db_password": "CGRateS.org", // password to use when connecting to stordb }, diff --git a/data/conf/samples/smg_gob/cgrates.json b/data/conf/samples/smg_mysql_gob/cgrates.json similarity index 93% rename from data/conf/samples/smg_gob/cgrates.json rename to data/conf/samples/smg_mysql_gob/cgrates.json index dc44bdb68..4ce9cbacd 100644 --- a/data/conf/samples/smg_gob/cgrates.json +++ b/data/conf/samples/smg_mysql_gob/cgrates.json @@ -21,6 +21,12 @@ }, }, +"data_db": { + "db_type": "redis", + "db_port": 6379, + "db_name": "10", +}, + "stor_db": { // database used to store offline tariff plans and CDRs "db_password": "CGRateS.org", // password to use when connecting to stordb }, diff --git a/data/conf/samples/smgreplcmaster_mongo/cgrates.json b/data/conf/samples/smgreplcmaster_mongo/cgrates.json new file mode 100644 index 000000000..9d49b8a87 --- /dev/null +++ b/data/conf/samples/smgreplcmaster_mongo/cgrates.json @@ -0,0 +1,71 @@ +{ +// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +// Copyright (C) ITsysCOM GmbH +"general": { + "log_level": 7, + "node_id":"MasterReplication", +}, + +"listen": { + "rpc_json": "127.0.0.1:2012", + "rpc_gob": "127.0.0.1:2013", + "http": "127.0.0.1:2080", +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rpc_conns": { + "rplConn": { + "strategy": "*broadcast_sync", + "conns": [{"address": "127.0.0.1:22012", "transport": "*json"}], + }, +}, + + +"rals": { + "enabled": true, +}, + +"schedulers": { + "enabled": true, +}, + +"cdrs": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "replication_conns": ["rplConn"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + +"apier": { + "scheduler_conns": ["*internal"], +}, + +} diff --git a/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json b/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json new file mode 100644 index 000000000..4d27b8425 --- /dev/null +++ b/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json @@ -0,0 +1,71 @@ +{ +// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +// Copyright (C) ITsysCOM GmbH +"general": { + "log_level": 7, + "node_id":"MasterReplication", +}, + +"listen": { + "rpc_json": "127.0.0.1:2012", + "rpc_gob": "127.0.0.1:2013", + "http": "127.0.0.1:2080", +}, + + +"rpc_conns": { + "rplConn": { + "strategy": "*broadcast_sync", + "conns": [{"address": "127.0.0.1:22013", "transport": "*gob"}], + }, +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, +}, + +"schedulers": { + "enabled": true, +}, + +"cdrs": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, + "replication_conns": ["rplConn"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + +"apier": { + "scheduler_conns": ["*internal"], +}, + +} diff --git a/data/conf/samples/smgreplcmaster/cgrates.json b/data/conf/samples/smgreplcmaster_mysql/cgrates.json similarity index 100% rename from data/conf/samples/smgreplcmaster/cgrates.json rename to data/conf/samples/smgreplcmaster_mysql/cgrates.json diff --git a/data/conf/samples/smgreplcmaster_gob/cgrates.json b/data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json similarity index 100% rename from data/conf/samples/smgreplcmaster_gob/cgrates.json rename to data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json diff --git a/data/conf/samples/smgreplcslave_mongo/cgrates.json b/data/conf/samples/smgreplcslave_mongo/cgrates.json new file mode 100644 index 000000000..fe0803ca0 --- /dev/null +++ b/data/conf/samples/smgreplcslave_mongo/cgrates.json @@ -0,0 +1,76 @@ +{ +// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +// Copyright (C) ITsysCOM GmbH +"general": { + "log_level": 7, + "node_id":"SlaveReplication", +}, + +"listen": { + "rpc_json": "127.0.0.1:22012", // RPC JSON listening address + "rpc_gob": "127.0.0.1:22013", // RPC GOB listening address + "http": "127.0.0.1:22080", // HTTP listening address +}, + +"rpc_conns": { + "conn1": { + "strategy": "*first", + "conns": [{"address": "127.0.0.1:22012", "transport":"*json"}], + }, + "rplConn": { + "strategy": "*broadcast_sync", + "conns": [{"address": "127.0.0.1:2012", "transport": "*json"}], + } +}, + + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, // enable Rater service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"schedulers": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, // starts SessionManager service: + "listen_bijson": "127.0.0.1:22014", // address where to listen for bidirectional JSON-RPC requests + "replication_conns": ["rplConn"], + "rals_conns": ["conn1"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + +"apier": { + "scheduler_conns": ["*internal"], +}, + +} diff --git a/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json b/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json new file mode 100644 index 000000000..2dcd47c12 --- /dev/null +++ b/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json @@ -0,0 +1,75 @@ +{ +// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +// Copyright (C) ITsysCOM GmbH +"general": { + "log_level": 7, + "node_id":"SlaveReplication", +}, + +"listen": { + "rpc_json": "127.0.0.1:22012", // RPC JSON listening address + "rpc_gob": "127.0.0.1:22013", // RPC GOB listening address + "http": "127.0.0.1:22080", // HTTP listening address +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", + "db_password": "", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", + "db_password": "", +}, + +"rals": { + "enabled": true, // enable Rater service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: +}, + +"schedulers": { + "enabled": true, +}, + +"attributes": { + "enabled": true, +}, + +"rpc_conns": { + "conn1": { + "strategy": "*first", + "conns": [{"address": "127.0.0.1:22013", "transport":"*gob"}], + }, + "rplConn": { + "strategy": "*broadcast_sync", + "conns": [{"address": "127.0.0.1:2013", "transport": "*gob"}], + } +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + +"sessions": { + "enabled": true, // starts SessionManager service: + "listen_bijson": "127.0.0.1:22014", // address where to listen for bidirectional JSON-RPC requests + "replication_conns": ["rplConn"], + "rals_conns": ["conn1"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + +"apier": { + "scheduler_conns": ["*internal"], +}, + +} diff --git a/data/conf/samples/smgreplcslave/cgrates.json b/data/conf/samples/smgreplcslave_mysql/cgrates.json similarity index 100% rename from data/conf/samples/smgreplcslave/cgrates.json rename to data/conf/samples/smgreplcslave_mysql/cgrates.json diff --git a/data/conf/samples/smgreplcslave_gob/cgrates.json b/data/conf/samples/smgreplcslave_mysql_gob/cgrates.json similarity index 100% rename from data/conf/samples/smgreplcslave_gob/cgrates.json rename to data/conf/samples/smgreplcslave_mysql_gob/cgrates.json diff --git a/integration_test.sh b/integration_test.sh index 35bfef774..e856c8b81 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -25,6 +25,9 @@ gnr_internal=$? echo 'go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*internal' go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*internal agts_internal=$? +echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*internal' +go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*internal +smg_internal=$? # SQL echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*sql' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*sql @@ -47,6 +50,9 @@ gnr_sql=$? echo 'go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*sql' go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*sql agts_sql=$? +echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*sql' +go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*sql +smg_sql=$? # Mongo echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo @@ -69,6 +75,9 @@ gnr_mongo=$? echo 'go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*mongo' go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*mongo agts_mongo=$? +echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*mongo' +go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*mongo +smg_mongo=$? # Postgres echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres @@ -91,24 +100,24 @@ gnr_postgres=$? echo 'go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*postgres' go test github.com/cgrates/cgrates/agents -tags=integration -dbtype=*postgres agts_postgres=$? +echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*postgres' +go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*postgres +smg_postgres=$? echo 'go test github.com/cgrates/cgrates/config -tags=integration' go test github.com/cgrates/cgrates/config -tags=integration cfg=$? -#All - -echo 'go test github.com/cgrates/cgrates/sessions -tags=integration' -go test github.com/cgrates/cgrates/sessions -tags=integration -smg=$? echo 'go test github.com/cgrates/cgrates/migrator -tags=integration' go test github.com/cgrates/cgrates/migrator -tags=integration mgr=$? -echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration' -go test github.com/cgrates/cgrates/dispatchers -tags=integration -dis=$? echo 'go test github.com/cgrates/cgrates/services -tags=integration' go test github.com/cgrates/cgrates/services -tags=integration srv=$? +#All + +echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration' +go test github.com/cgrates/cgrates/dispatchers -tags=integration +dis=$? echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline' go test github.com/cgrates/cgrates/apier/v1 -tags=offline offline=$? diff --git a/migrator/accounts_it_test.go b/migrator/accounts_it_test.go index 18e25395c..da149d97f 100755 --- a/migrator/accounts_it_test.go +++ b/migrator/accounts_it_test.go @@ -41,14 +41,14 @@ var ( accMigrator *Migrator accAction string dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") + + sTestsAccIT = []func(t *testing.T){ + testAccITConnect, + testAccITFlush, + testAccITMigrateAndMove, + } ) -var sTestsAccIT = []func(t *testing.T){ - testAccITConnect, - testAccITFlush, - testAccITMigrateAndMove, -} - func TestAccountMigrateITRedis(t *testing.T) { var err error accPathIn = path.Join(*dataDir, "conf", "samples", "tutmysql") diff --git a/sessions/lib_test.go b/sessions/lib_test.go new file mode 100644 index 000000000..c6cdc9458 --- /dev/null +++ b/sessions/lib_test.go @@ -0,0 +1,47 @@ +/* +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 sessions + +import ( + "errors" + "flag" + "net/rpc" + "net/rpc/jsonrpc" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/utils" +) + +var ( + dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") + waitRater = flag.Int("wait_rater", 500, "Number of miliseconds to wait for rater to start and cache") + encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication") + dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") +) + +func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { + switch *encoding { + case utils.MetaJSON: + return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) + case utils.MetaGOB: + return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + default: + return nil, errors.New("UNSUPPORTED_RPC") + } +} diff --git a/sessions/sessions_birpc_it_test.go b/sessions/sessions_birpc_it_test.go index 47a7c519c..7c226a914 100644 --- a/sessions/sessions_birpc_it_test.go +++ b/sessions/sessions_birpc_it_test.go @@ -33,12 +33,43 @@ import ( var ( sessionsBiRPCCfgPath string + sessionsBiRPCCfgDIR string sessionsBiRPCCfg *config.CGRConfig sessionsBiRPC *rpc2.Client disconnectEvChan = make(chan *utils.AttrDisconnectSession, 1) err error + sessionsTests = []func(t *testing.T){ + testSessionsBiRPCInitCfg, + testSessionsBiRPCResetDataDb, + testSessionsBiRPCResetStorDb, + testSessionsBiRPCStartEngine, + testSessionsBiRPCApierRpcConn, + testSessionsBiRPCTPFromFolder, + testSessionsBiRPCSessionAutomaticDisconnects, + testSessionsBiRPCSessionOriginatorTerminate, + testSessionsBiRPCStopCgrEngine, + } ) +// Tests starts here +func TestSessionsBiRPC(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + sessionsBiRPCCfgDIR = "smg_automatic_debits_internal" + case utils.MetaSQL: + sessionsBiRPCCfgDIR = "smg_automatic_debits_mysql" + case utils.MetaMongo: + sessionsBiRPCCfgDIR = "smg_automatic_debits_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + for _, stest := range sessionsTests { + t.Run(sessionsBiRPCCfgDIR, stest) + } +} + func handleDisconnectSession(clnt *rpc2.Client, args *utils.AttrDisconnectSession, reply *string) error { disconnectEvChan <- args @@ -46,8 +77,8 @@ func handleDisconnectSession(clnt *rpc2.Client, return nil } -func TestSessionsBiRPCInitCfg(t *testing.T) { - sessionsBiRPCCfgPath = path.Join(*dataDir, "conf", "samples", "smg_automatic_debits") +func testSessionsBiRPCInitCfg(t *testing.T) { + sessionsBiRPCCfgPath = path.Join(*dataDir, "conf", "samples", sessionsBiRPCCfgDIR) // Init config first sessionsBiRPCCfg, err = config.NewCGRConfigFromPath(sessionsBiRPCCfgPath) if err != nil { @@ -58,28 +89,28 @@ func TestSessionsBiRPCInitCfg(t *testing.T) { } // Remove data in both rating and accounting db -func TestSessionsBiRPCResetDataDb(t *testing.T) { +func testSessionsBiRPCResetDataDb(t *testing.T) { if err := engine.InitDataDb(sessionsBiRPCCfg); err != nil { t.Fatal(err) } } // Wipe out the cdr database -func TestSessionsBiRPCResetStorDb(t *testing.T) { +func testSessionsBiRPCResetStorDb(t *testing.T) { if err := engine.InitStorDb(sessionsBiRPCCfg); err != nil { t.Fatal(err) } } // Start CGR Engine -func TestSessionsBiRPCStartEngine(t *testing.T) { +func testSessionsBiRPCStartEngine(t *testing.T) { if _, err := engine.StopStartEngine(sessionsBiRPCCfgPath, *waitRater); err != nil { t.Fatal(err) } } // Connect rpc client to rater -func TestSessionsBiRPCApierRpcConn(t *testing.T) { +func testSessionsBiRPCApierRpcConn(t *testing.T) { clntHandlers := map[string]interface{}{utils.SessionSv1DisconnectSession: handleDisconnectSession} dummyClnt, err := utils.NewBiJSONrpcClient(sessionsBiRPCCfg.SessionSCfg().ListenBijson, clntHandlers) @@ -97,7 +128,7 @@ func TestSessionsBiRPCApierRpcConn(t *testing.T) { } // Load the tariff plan, creating accounts and their balances -func TestSessionsBiRPCTPFromFolder(t *testing.T) { +func testSessionsBiRPCTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance if err := sessionsRPC.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { @@ -106,7 +137,7 @@ func TestSessionsBiRPCTPFromFolder(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } -func TestSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { +func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { // Create a balance with 1 second inside and rating increments of 1ms (to be compatible with debit interval) attrSetBalance := utils.AttrSetBalance{Tenant: "cgrates.org", Account: "TestSessionsBiRPCSessionAutomaticDisconnects", @@ -232,7 +263,7 @@ func TestSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { } } -func TestSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { +func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { attrSetBalance := utils.AttrSetBalance{ Tenant: "cgrates.org", Account: "TestSessionsBiRPCSessionOriginatorTerminate", @@ -350,7 +381,7 @@ func TestSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { } } -func TestSessionsBiRPCStopCgrEngine(t *testing.T) { +func testSessionsBiRPCStopCgrEngine(t *testing.T) { if err := sessionsBiRPC.Close(); err != nil { // Close the connection so we don't get EOF warnings from client t.Error(err) } diff --git a/sessions/sessions_data_it_test.go b/sessions/sessions_data_it_test.go index fc1b9cbb1..b52fd7748 100644 --- a/sessions/sessions_data_it_test.go +++ b/sessions/sessions_data_it_test.go @@ -30,16 +30,54 @@ import ( "github.com/cgrates/cgrates/utils" ) -var dataCfgPath string -var dataCfg *config.CGRConfig -var sDataRPC *rpc.Client +var ( + dataCfgPath string + dataCfgDIR string + dataCfg *config.CGRConfig + sDataRPC *rpc.Client -func TestSessionsDataInitCfg(t *testing.T) { - dataCfgPath = path.Join(*dataDir, "conf", "samples", "smg") - if *encoding == utils.MetaGOB { - dataCfgPath = path.Join(*dataDir, "conf", "samples", "smg_gob") + SessionsDataTests = []func(t *testing.T){ + testSessionsDataInitCfg, + testSessionsDataResetDataDb, + testSessionsDataResetStorDb, + testSessionsDataStartEngine, + testSessionsDataApierRpcConn, + testSessionsDataTPFromFolder, + testSessionsDataLastUsedData, + testSessionsDataLastUsedMultipleUpdates, + testSessionsDataTTLExpired, + testSessionsDataTTLExpMultiUpdates, + testSessionsDataMultipleDataNoUsage, + testSessionsDataTTLUsageProtection, + testSessionsDataTTKillEngine, } - // Init config first +) + +// Tests starts here +func TestSessionsData(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + dataCfgDIR = "smg_internal" + case utils.MetaSQL: + dataCfgDIR = "smg_mysql" + case utils.MetaMongo: + dataCfgDIR = "smg_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + if *encoding == utils.MetaGOB { + dataCfgDIR += "_gob" + } + for _, stest := range SessionsDataTests { + t.Run(dataCfgDIR, stest) + } +} + +// Init config first +func testSessionsDataInitCfg(t *testing.T) { + dataCfgPath = path.Join(*dataDir, "conf", "samples", dataCfgDIR) var err error dataCfg, err = config.NewCGRConfigFromPath(dataCfgPath) if err != nil { @@ -50,28 +88,28 @@ func TestSessionsDataInitCfg(t *testing.T) { } // Remove data in both rating and accounting db -func TestSessionsDataResetDataDb(t *testing.T) { +func testSessionsDataResetDataDb(t *testing.T) { if err := engine.InitDataDb(dataCfg); err != nil { t.Fatal(err) } } // Wipe out the cdr database -func TestSessionsDataResetStorDb(t *testing.T) { +func testSessionsDataResetStorDb(t *testing.T) { if err := engine.InitStorDb(dataCfg); err != nil { t.Fatal(err) } } // Start CGR Engine -func TestSessionsDataStartEngine(t *testing.T) { +func testSessionsDataStartEngine(t *testing.T) { if _, err := engine.StopStartEngine(dataCfgPath, *waitRater); err != nil { t.Fatal(err) } } // Connect rpc client to rater -func TestSessionsDataApierRpcConn(t *testing.T) { +func testSessionsDataApierRpcConn(t *testing.T) { var err error sDataRPC, err = newRPCClient(dataCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed if err != nil { @@ -80,7 +118,7 @@ func TestSessionsDataApierRpcConn(t *testing.T) { } // Load the tariff plan, creating accounts and their balances -func TestSessionsDataTPFromFolder(t *testing.T) { +func testSessionsDataTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance if err := sDataRPC.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { @@ -89,7 +127,7 @@ func TestSessionsDataTPFromFolder(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } -func TestSessionsDataLastUsedData(t *testing.T) { +func testSessionsDataLastUsedData(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 102400.0 @@ -230,7 +268,7 @@ func TestSessionsDataLastUsedData(t *testing.T) { } } -func TestSessionsDataLastUsedMultipleUpdates(t *testing.T) { +func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { var acnt *engine.Account acntAttrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "TestSessionsDataLastUsedMultipleData"} @@ -505,7 +543,7 @@ func TestSessionsDataLastUsedMultipleUpdates(t *testing.T) { } } -func TestSessionsDataTTLExpired(t *testing.T) { +func testSessionsDataTTLExpired(t *testing.T) { var acnt *engine.Account acntAttrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "TestSessionsDataTTLExpired"} @@ -579,7 +617,7 @@ func TestSessionsDataTTLExpired(t *testing.T) { } } -func TestSessionsDataTTLExpMultiUpdates(t *testing.T) { +func testSessionsDataTTLExpMultiUpdates(t *testing.T) { var acnt *engine.Account acntAttrs := &utils.AttrGetAccount{ @@ -708,7 +746,7 @@ func TestSessionsDataTTLExpMultiUpdates(t *testing.T) { } } -func TestSessionsDataMultipleDataNoUsage(t *testing.T) { +func testSessionsDataMultipleDataNoUsage(t *testing.T) { var acnt *engine.Account acntAttrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "TestSessionsDataTTLExpMultiUpdates"} @@ -916,7 +954,7 @@ func TestSessionsDataMultipleDataNoUsage(t *testing.T) { // TestSessionsDataTTLUsageProtection makes sure that original TTL (50ms) // limits the additional debit without overloading memory -func TestSessionsDataTTLUsageProtection(t *testing.T) { +func testSessionsDataTTLUsageProtection(t *testing.T) { var acnt *engine.Account acntAttrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "TestSessionsDataTTLUsageProtection"} @@ -993,7 +1031,7 @@ func TestSessionsDataTTLUsageProtection(t *testing.T) { } } -func TestSessionsDataTTKillEngine(t *testing.T) { +func testSessionsDataTTKillEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) } diff --git a/sessions/sessions_it_test.go b/sessions/sessions_it_test.go index fab472217..cc651beef 100644 --- a/sessions/sessions_it_test.go +++ b/sessions/sessions_it_test.go @@ -31,16 +31,51 @@ import ( "github.com/cgrates/cgrates/utils" ) -var sItCfgPath string -var sItCfg *config.CGRConfig -var sItRPC *rpc.Client +var ( + sItCfgPath string + sItCfgDIR string + sItCfg *config.CGRConfig + sItRPC *rpc.Client -func TestSessionsItInitCfg(t *testing.T) { - sItCfgPath = path.Join(*dataDir, "conf", "samples", "smg") - if *encoding == utils.MetaGOB { - dataCfgPath = path.Join(*dataDir, "conf", "samples", "smg_gob") + sessionsITtests = []func(t *testing.T){ + testSessionsItInitCfg, + testSessionsItResetDataDb, + testSessionsItResetStorDb, + testSessionsItStartEngine, + testSessionsItApierRpcConn, + testSessionsItTPFromFolder, + testSessionsItTerminatUnexist, + testSessionsItUpdateUnexist, + testSessionsItTerminatePassive, + testSessionsItEventCostCompressing, + testSessionsItStopCgrEngine, } - // Init config first +) + +func TestSessionsIt(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + sItCfgDIR = "smg_internal" + case utils.MetaSQL: + sItCfgDIR = "smg_mysql" + case utils.MetaMongo: + sItCfgDIR = "smg_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + if *encoding == utils.MetaGOB { + sItCfgDIR += "_gob" + } + for _, stest := range sessionsITtests { + t.Run(sItCfgDIR, stest) + } +} + +// Init config firs +func testSessionsItInitCfg(t *testing.T) { + sItCfgPath = path.Join(*dataDir, "conf", "samples", sItCfgDIR) var err error sItCfg, err = config.NewCGRConfigFromPath(sItCfgPath) if err != nil { @@ -51,28 +86,28 @@ func TestSessionsItInitCfg(t *testing.T) { } // Remove data in both rating and accounting db -func TestSessionsItResetDataDb(t *testing.T) { +func testSessionsItResetDataDb(t *testing.T) { if err := engine.InitDataDb(sItCfg); err != nil { t.Fatal(err) } } // Wipe out the cdr database -func TestSessionsItResetStorDb(t *testing.T) { +func testSessionsItResetStorDb(t *testing.T) { if err := engine.InitStorDb(sItCfg); err != nil { t.Fatal(err) } } // Start CGR Engine -func TestSessionsItStartEngine(t *testing.T) { +func testSessionsItStartEngine(t *testing.T) { if _, err := engine.StopStartEngine(sItCfgPath, *waitRater); err != nil { t.Fatal(err) } } // Connect rpc client to rater -func TestSessionsItApierRpcConn(t *testing.T) { +func testSessionsItApierRpcConn(t *testing.T) { var err error sItRPC, err = newRPCClient(sItCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed if err != nil { @@ -81,7 +116,7 @@ func TestSessionsItApierRpcConn(t *testing.T) { } // Load the tariff plan, creating accounts and their balances -func TestSessionsItTPFromFolder(t *testing.T) { +func testSessionsItTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} var loadInst utils.LoadInstance if err := sItRPC.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { @@ -90,7 +125,7 @@ func TestSessionsItTPFromFolder(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } -func TestSessionsItTerminatUnexist(t *testing.T) { +func testSessionsItTerminatUnexist(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 10.0 @@ -163,7 +198,7 @@ func TestSessionsItTerminatUnexist(t *testing.T) { } -func TestSessionsItUpdateUnexist(t *testing.T) { +func testSessionsItUpdateUnexist(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 9.299800 @@ -241,7 +276,7 @@ func TestSessionsItUpdateUnexist(t *testing.T) { } } -func TestSessionsItTerminatePassive(t *testing.T) { +func testSessionsItTerminatePassive(t *testing.T) { //create the event for session sEv := engine.NewMapEvent(map[string]interface{}{ utils.EVENT_NAME: "UpdateEvent", @@ -335,7 +370,7 @@ func TestSessionsItTerminatePassive(t *testing.T) { } -func TestSessionsItEventCostCompressing(t *testing.T) { +func testSessionsItEventCostCompressing(t *testing.T) { attrSetBalance := utils.AttrSetBalance{ Tenant: "cgrates.org", Account: "TestSessionsItEventCostCompressing", @@ -445,7 +480,7 @@ func TestSessionsItEventCostCompressing(t *testing.T) { } -func TestSessionsItStopCgrEngine(t *testing.T) { +func testSessionsItStopCgrEngine(t *testing.T) { if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) } diff --git a/sessions/sessions_rpl_it_test.go b/sessions/sessions_rpl_it_test.go index 90707cb15..1e0916739 100644 --- a/sessions/sessions_rpl_it_test.go +++ b/sessions/sessions_rpl_it_test.go @@ -31,31 +31,66 @@ import ( "github.com/cgrates/cgrates/utils" ) -var smgRplcMasterCfgPath, smgRplcSlaveCfgPath string -var smgRplcMasterCfg, smgRplcSlaveCfg *config.CGRConfig -var smgRplcMstrRPC, smgRplcSlvRPC *rpc.Client +var ( + smgRplcMasterCfgPath, smgRplcSlaveCfgPath string + smgRplcMasterCfgDIR, smgRplcSlaveCfgDIR string + smgRplcMasterCfg, smgRplcSlaveCfg *config.CGRConfig + smgRplcMstrRPC, smgRplcSlvRPC *rpc.Client -func TestSessionSRplInitCfg(t *testing.T) { - smgRplcMasterCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcmaster") - if *encoding == utils.MetaGOB { - smgRplcMasterCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcmaster_gob") + SessionsRplTests = []func(t *testing.T){ + testSessionSRplInitCfg, + testSessionSRplResetDB, + testSessionSRplStartEngine, + testSessionSRplApierRpcConn, + testSessionSRplTPFromFolder, + testSessionSRplInitiate, + testSessionSRplUpdate, + testSessionSRplTerminate, + testSessionSRplManualReplicate, + testSessionSRplActivateSessions, + testSessionSRplStopCgrEngine, } +) + +func TestSessionSRpl(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + t.SkipNow() + case utils.MetaSQL: + smgRplcMasterCfgDIR = "smgreplcmaster_mysql" + smgRplcSlaveCfgDIR = "smgreplcslave_mysql" + case utils.MetaMongo: + smgRplcMasterCfgDIR = "smgreplcmaster_mongo" + smgRplcSlaveCfgDIR = "smgreplcslave_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } + if *encoding == utils.MetaGOB { + smgRplcMasterCfgDIR += "_gob" + smgRplcSlaveCfgDIR += "_gob" + } + for _, stest := range SessionsRplTests { + t.Run(*dbType, stest) + } +} + +func testSessionSRplInitCfg(t *testing.T) { + smgRplcMasterCfgPath = path.Join(*dataDir, "conf", "samples", smgRplcMasterCfgDIR) if smgRplcMasterCfg, err = config.NewCGRConfigFromPath(smgRplcMasterCfgPath); err != nil { t.Fatal(err) } smgRplcMasterCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush() config.SetCgrConfig(smgRplcMasterCfg) - smgRplcSlaveCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcslave") - if *encoding == utils.MetaGOB { - smgRplcSlaveCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcslave_gob") - } + smgRplcSlaveCfgPath = path.Join(*dataDir, "conf", "samples", smgRplcSlaveCfgDIR) if smgRplcSlaveCfg, err = config.NewCGRConfigFromPath(smgRplcSlaveCfgPath); err != nil { t.Fatal(err) } } // Remove data in both rating and accounting db -func TestSessionSRplResetDB(t *testing.T) { +func testSessionSRplResetDB(t *testing.T) { if err := engine.InitDataDb(smgRplcMasterCfg); err != nil { t.Fatal(err) } @@ -65,7 +100,7 @@ func TestSessionSRplResetDB(t *testing.T) { } // Start CGR Engine -func TestSessionSRplStartEngine(t *testing.T) { +func testSessionSRplStartEngine(t *testing.T) { if _, err := engine.StopStartEngine(smgRplcSlaveCfgPath, *waitRater); err != nil { // Start slave before master t.Fatal(err) } @@ -75,7 +110,7 @@ func TestSessionSRplStartEngine(t *testing.T) { } // Connect rpc client to rater -func TestSessionSRplApierRpcConn(t *testing.T) { +func testSessionSRplApierRpcConn(t *testing.T) { if smgRplcMstrRPC, err = newRPCClient(smgRplcMasterCfg.ListenCfg()); err != nil { t.Fatal(err) } @@ -85,7 +120,7 @@ func TestSessionSRplApierRpcConn(t *testing.T) { } // Load the tariff plan, creating accounts and their balances -func TestSessionSRplTPFromFolder(t *testing.T) { +func testSessionSRplTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance if err := smgRplcMstrRPC.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { @@ -94,7 +129,7 @@ func TestSessionSRplTPFromFolder(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } -func TestSessionSRplInitiate(t *testing.T) { +func testSessionSRplInitiate(t *testing.T) { var aSessions []*ExternalSession //make sure we don't have active sessions on master and passive on slave if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, @@ -170,7 +205,7 @@ func TestSessionSRplInitiate(t *testing.T) { } } -func TestSessionSRplUpdate(t *testing.T) { +func testSessionSRplUpdate(t *testing.T) { //update the session on slave so the session should became active usage := time.Duration(1 * time.Minute) argsUpdate := &V1UpdateSessionArgs{ @@ -250,7 +285,7 @@ func TestSessionSRplUpdate(t *testing.T) { } } -func TestSessionSRplTerminate(t *testing.T) { +func testSessionSRplTerminate(t *testing.T) { args := &V1TerminateSessionArgs{ TerminateSession: true, CGREvent: &utils.CGREvent{ @@ -305,7 +340,7 @@ func TestSessionSRplTerminate(t *testing.T) { } } -func TestSessionSRplManualReplicate(t *testing.T) { +func testSessionSRplManualReplicate(t *testing.T) { masterProc, err := engine.StopStartEngine(smgRplcMasterCfgPath, *waitRater) if err != nil { // Kill both and start Master t.Fatal(err) @@ -458,7 +493,7 @@ func TestSessionSRplManualReplicate(t *testing.T) { } } -func TestSessionSRplActivateSessions(t *testing.T) { +func testSessionSRplActivateSessions(t *testing.T) { var aSessions []*ExternalSession var reply string // Activate first session (with ID: ede927f8e42318a8db02c0f74adc2d9e16770339) @@ -510,7 +545,7 @@ func TestSessionSRplActivateSessions(t *testing.T) { } } -func TestSessionSRplStopCgrEngine(t *testing.T) { +func testSessionSRplStopCgrEngine(t *testing.T) { if err := engine.KillEngine(1000); err != nil { t.Error(err) } diff --git a/sessions/sessions_voice_it_test.go b/sessions/sessions_voice_it_test.go index 7c9f5a532..9dcb6182e 100644 --- a/sessions/sessions_voice_it_test.go +++ b/sessions/sessions_voice_it_test.go @@ -20,11 +20,8 @@ along with this program. If not, see package sessions import ( - "errors" - "flag" "fmt" "net/rpc" - "net/rpc/jsonrpc" "path" "testing" "time" @@ -35,31 +32,54 @@ import ( ) var ( - waitRater = flag.Int("wait_rater", 150, "Number of miliseconds to wait for rater to start and cache") - dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") - voiceCfgPath string + voiceCfgDIR string voiceCfg *config.CGRConfig sessionsRPC *rpc.Client - encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication") + + sessionsVoiceTests = []func(t *testing.T){ + testSessionsVoiceInitCfg, + testSessionsVoiceResetDataDb, + testSessionsVoiceResetStorDb, + testSessionsVoiceStartEngine, + testSessionsVoiceApierRpcConn, + testSessionsVoiceTPFromFolder, + testSessionsVoiceMonetaryRefund, + testSessionsVoiceVoiceRefund, + testSessionsVoiceMixedRefund, + testSessionsVoiceLastUsed, + testSessionsVoiceLastUsedEnd, + testSessionsVoiceLastUsedNotFixed, + testSessionsVoiceSessionTTL, + testSessionsVoiceSessionTTLWithRelocate, + testSessionsVoiceRelocateWithOriginIDPrefix, + testSessionsVoiceStopCgrEngine, + } ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { - switch *encoding { - case utils.MetaJSON: - return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) - case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) +func TestSessionsVoice(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + voiceCfgDIR = "smg_internal" + case utils.MetaSQL: + voiceCfgDIR = "smg_mysql" + case utils.MetaMongo: + voiceCfgDIR = "smg_mongo" + case utils.MetaPostgres: + t.SkipNow() default: - return nil, errors.New("UNSUPPORTED_RPC") + t.Fatal("Unknown Database type") + } + if *encoding == utils.MetaGOB { + voiceCfgDIR += "_gob" + } + for _, stest := range sessionsVoiceTests { + t.Run(voiceCfgDIR, stest) } } -func TestSessionsVoiceInitCfg(t *testing.T) { - voiceCfgPath = path.Join(*dataDir, "conf", "samples", "smg") - if *encoding == utils.MetaGOB { - dataCfgPath = path.Join(*dataDir, "conf", "samples", "smg_gob") - } +func testSessionsVoiceInitCfg(t *testing.T) { + voiceCfgPath = path.Join(*dataDir, "conf", "samples", voiceCfgDIR) // Init config first var err error voiceCfg, err = config.NewCGRConfigFromPath(voiceCfgPath) @@ -71,28 +91,28 @@ func TestSessionsVoiceInitCfg(t *testing.T) { } // Remove data in both rating and accounting db -func TestSessionsVoiceResetDataDb(t *testing.T) { +func testSessionsVoiceResetDataDb(t *testing.T) { if err := engine.InitDataDb(voiceCfg); err != nil { t.Fatal(err) } } // Wipe out the cdr database -func TestSessionsVoiceResetStorDb(t *testing.T) { +func testSessionsVoiceResetStorDb(t *testing.T) { if err := engine.InitStorDb(voiceCfg); err != nil { t.Fatal(err) } } // Start CGR Engine -func TestSessionsVoiceStartEngine(t *testing.T) { +func testSessionsVoiceStartEngine(t *testing.T) { if _, err := engine.StopStartEngine(voiceCfgPath, *waitRater); err != nil { t.Fatal(err) } } // Connect rpc client to rater -func TestSessionsVoiceApierRpcConn(t *testing.T) { +func testSessionsVoiceApierRpcConn(t *testing.T) { var err error sessionsRPC, err = newRPCClient(voiceCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed if err != nil { @@ -101,7 +121,7 @@ func TestSessionsVoiceApierRpcConn(t *testing.T) { } // Load the tariff plan, creating accounts and their balances -func TestSessionsVoiceTPFromFolder(t *testing.T) { +func testSessionsVoiceTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance if err := sessionsRPC.Call(utils.ApierV2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { @@ -110,7 +130,7 @@ func TestSessionsVoiceTPFromFolder(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } -func TestSessionsVoiceMonetaryRefund(t *testing.T) { +func testSessionsVoiceMonetaryRefund(t *testing.T) { usage := time.Duration(1*time.Minute + 30*time.Second) initArgs := &V1InitSessionArgs{ InitSession: true, @@ -187,7 +207,7 @@ func TestSessionsVoiceMonetaryRefund(t *testing.T) { } } -func TestSessionsVoiceVoiceRefund(t *testing.T) { +func testSessionsVoiceVoiceRefund(t *testing.T) { usage := time.Duration(1*time.Minute + 30*time.Second) initArgs := &V1InitSessionArgs{ InitSession: true, @@ -266,7 +286,7 @@ func TestSessionsVoiceVoiceRefund(t *testing.T) { } } -func TestSessionsVoiceMixedRefund(t *testing.T) { +func testSessionsVoiceMixedRefund(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} if err := sessionsRPC.Call(utils.ApierV2GetAccount, attrs, &acnt); err != nil { @@ -360,7 +380,7 @@ func TestSessionsVoiceMixedRefund(t *testing.T) { //t.Logf("After voice: %f", acnt.BalanceMap[utils.VOICE].GetTotalValue()) } -func TestSessionsVoiceLastUsed(t *testing.T) { +func testSessionsVoiceLastUsed(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 8.790000 @@ -521,7 +541,7 @@ func TestSessionsVoiceLastUsed(t *testing.T) { } } -func TestSessionsVoiceLastUsedEnd(t *testing.T) { +func testSessionsVoiceLastUsedEnd(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 7.59000 @@ -643,7 +663,7 @@ func TestSessionsVoiceLastUsedEnd(t *testing.T) { } } -func TestSessionsVoiceLastUsedNotFixed(t *testing.T) { +func testSessionsVoiceLastUsedNotFixed(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 6.59000 @@ -765,7 +785,7 @@ func TestSessionsVoiceLastUsedNotFixed(t *testing.T) { } } -func TestSessionsVoiceSessionTTL(t *testing.T) { +func testSessionsVoiceSessionTTL(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 5.590000 @@ -919,7 +939,7 @@ func TestSessionsVoiceSessionTTL(t *testing.T) { } } -func TestSessionsVoiceSessionTTLWithRelocate(t *testing.T) { +func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { attrSetBalance := utils.AttrSetBalance{ Tenant: "cgrates.org", Account: "TestTTLWithRelocate", @@ -1092,7 +1112,7 @@ func TestSessionsVoiceSessionTTLWithRelocate(t *testing.T) { } } -func TestSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { +func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { attrSetBalance := utils.AttrSetBalance{ Tenant: "cgrates.org", Account: "TestRelocateWithOriginIDPrefix", @@ -1346,7 +1366,7 @@ func TestSMGDataDerivedChargingNoCredit(t *testing.T) { */ // ToDo: Add test for ChargeEvent with derived charging, one with debit possible and second not so we see refund and error.CreditInsufficient showing up. -func TestSessionsVoiceStopCgrEngine(t *testing.T) { +func testSessionsVoiceStopCgrEngine(t *testing.T) { if err := engine.KillEngine(1000); err != nil { t.Error(err) }