mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Add removed test back
This commit is contained in:
committed by
Dan Christian Bogos
parent
7fc6344827
commit
5f8812f012
@@ -20,3 +20,288 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package general_tests
|
||||
|
||||
// import (
|
||||
// "flag"
|
||||
// "net/rpc"
|
||||
// "os"
|
||||
// "os/exec"
|
||||
// "path"
|
||||
// "reflect"
|
||||
// "strconv"
|
||||
// "testing"
|
||||
|
||||
// "github.com/cgrates/cgrates/config"
|
||||
// "github.com/cgrates/cgrates/engine"
|
||||
// "github.com/cgrates/cgrates/utils"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// node1ConfigPath = path.Join(*dataDir, "redisSentinel", "node1.conf")
|
||||
// node2ConfigPath = path.Join(*dataDir, "redisSentinel", "node2.conf")
|
||||
// sentinel1ConfigPath = path.Join(*dataDir, "redisSentinel", "sentinel1.conf")
|
||||
// sentinel2ConfigPath = path.Join(*dataDir, "redisSentinel", "sentinel2.conf")
|
||||
// engineConfigPath = path.Join(*dataDir, "conf", "samples", "redisSentinel")
|
||||
// sentinelConfig *config.CGRConfig
|
||||
// sentinelRPC *rpc.Client
|
||||
// node1Exec *exec.Cmd
|
||||
// node2Exec *exec.Cmd
|
||||
// stlExec1 *exec.Cmd
|
||||
// stlExec2 *exec.Cmd
|
||||
// redisSentinel = flag.Bool("redisSentinel", false, "Run tests with redis sentinel")
|
||||
|
||||
// sTestsRds = []func(t *testing.T){
|
||||
// testRedisSentinelStartNodes,
|
||||
// testRedisSentinelInitConfig,
|
||||
// testRedisSentinelFlushDb,
|
||||
// testRedisSentinelStartEngine,
|
||||
// testRedisSentinelRPCCon,
|
||||
// testRedisSentinelSetGetAttribute,
|
||||
// testRedisSentinelInsertion,
|
||||
// testRedisSentinelGetAttrAfterFailover,
|
||||
// testRedisSentinelKillEngine,
|
||||
// }
|
||||
// )
|
||||
|
||||
// // Before running these tests make sure node1.conf, node2.conf, sentinel1.conf are the next
|
||||
// // Node1 will be master and start at port 16379
|
||||
// // Node2 will be slave of node1 and start at port 16380
|
||||
// // Sentinel1 will be started at port 16381 and will watch Node1
|
||||
// // Sentinel2 will be started at port 16382 and will watch Node1
|
||||
// // Also make sure that redis process is stopped
|
||||
// func TestRedisSentinel(t *testing.T) {
|
||||
// if !*redisSentinel {
|
||||
// return
|
||||
// }
|
||||
// switch *dbType {
|
||||
// case utils.MetaMySQL:
|
||||
// case utils.MetaInternal,
|
||||
// utils.MetaMongo,
|
||||
// utils.MetaPostgres:
|
||||
// t.SkipNow()
|
||||
// default:
|
||||
// t.Fatal("Unknown Database type")
|
||||
// }
|
||||
// for _, stest := range sTestsRds {
|
||||
// t.Run("TestRedisSentinel", stest)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelStartNodes(t *testing.T) {
|
||||
// if err := os.MkdirAll("/tmp/sentinel/", 0755); err != nil {
|
||||
// t.Fatal("Error creating folder: /tmp/sentinel/ ", err)
|
||||
// }
|
||||
|
||||
// node1Exec = exec.Command("redis-server", node1ConfigPath)
|
||||
// if err := node1Exec.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// node2Exec = exec.Command("redis-server", node2ConfigPath)
|
||||
// if err := node2Exec.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// stlExec1 = exec.Command("redis-sentinel", sentinel1ConfigPath)
|
||||
// if err := stlExec1.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// stlExec2 = exec.Command("redis-sentinel", sentinel2ConfigPath)
|
||||
// if err := stlExec2.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelInitConfig(t *testing.T) {
|
||||
// var err error
|
||||
// sentinelConfig, err = config.NewCGRConfigFromPath(engineConfigPath)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelFlushDb(t *testing.T) {
|
||||
// if err := engine.InitDataDB(sentinelConfig); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelStartEngine(t *testing.T) {
|
||||
// if _, err := engine.StopStartEngine(engineConfigPath, 2000); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelRPCCon(t *testing.T) {
|
||||
// var err error
|
||||
// sentinelRPC, err = newRPCClient(sentinelConfig.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelSetGetAttribute(t *testing.T) {
|
||||
// alsPrf := &engine.AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ApierTest",
|
||||
// FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*opts.*context:*sessions|*cdrs"},
|
||||
// Attributes: []*engine.Attribute{
|
||||
// {
|
||||
// Path: utils.MetaReq + utils.NestingSep + utils.Subject,
|
||||
// Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
|
||||
// },
|
||||
// },
|
||||
// Weight: 20,
|
||||
// }
|
||||
// alsPrf.Compile()
|
||||
// var result string
|
||||
// if err := sentinelRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if result != utils.OK {
|
||||
// t.Error("Unexpected reply returned", result)
|
||||
// }
|
||||
// var reply *engine.AttributeProfile
|
||||
// if err := sentinelRPC.Call(utils.APIerSv1GetAttributeProfile,
|
||||
// &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// reply.Compile()
|
||||
// if !reflect.DeepEqual(alsPrf, reply) {
|
||||
// t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelInsertion(t *testing.T) {
|
||||
// var nrFails1, nrFails2 int
|
||||
// alsPrf := &engine.AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ApierTest",
|
||||
// FilterIDs: []string{"*string:~*reqAccount:1001", "*string:~*opts.*context:*sessions|*cdrs"},
|
||||
// Attributes: []*engine.Attribute{
|
||||
// {
|
||||
// Path: utils.MetaReq + utils.NestingSep + utils.Subject,
|
||||
// Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
|
||||
// },
|
||||
// },
|
||||
// Weight: 20,
|
||||
// }
|
||||
// orgiginID := alsPrf.ID + "_"
|
||||
// index := 0
|
||||
// var result string
|
||||
// addFunc := func(t *testing.T, nrFail *int) {
|
||||
// alsPrf.ID = orgiginID + strconv.Itoa(index)
|
||||
// if err := sentinelRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
|
||||
// if err.Error() == "SERVER_ERROR: EOF" {
|
||||
// *nrFail = *nrFail + 1
|
||||
// } else {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
// index++
|
||||
// }
|
||||
// forFunc1 := func(t *testing.T) {
|
||||
// for i := 0; i < 25; i++ {
|
||||
// t.Run("add", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// addFunc(t, &nrFails1)
|
||||
// })
|
||||
// if i == 5 {
|
||||
// t.Run("stop1", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// if err := node1Exec.Process.Kill(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if err := stlExec1.Process.Kill(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// if i == 10 {
|
||||
// t.Run("stop2", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// if err := node2Exec.Process.Kill(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if err := stlExec2.Process.Kill(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// t.Run("add2", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// addFunc(t, &nrFails1)
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// forFunc2 := func(t *testing.T) {
|
||||
// for i := 0; i < 10; i++ {
|
||||
// t.Run("add", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// addFunc(t, &nrFails2)
|
||||
// })
|
||||
// t.Run("add2", func(t *testing.T) {
|
||||
// t.Parallel()
|
||||
// addFunc(t, &nrFails2)
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// t.Run("for1", forFunc1)
|
||||
// if nrFails1 == 0 {
|
||||
// t.Error("Fail tests in case of failover")
|
||||
// }
|
||||
// node1Exec = exec.Command("redis-server", node1ConfigPath)
|
||||
// if err := node1Exec.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// node2Exec = exec.Command("redis-server", node2ConfigPath)
|
||||
// if err := node2Exec.Start(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// t.Run("for2", forFunc2)
|
||||
// if nrFails2 > 19 {
|
||||
// t.Errorf("Fail tests in case of failback ")
|
||||
// }
|
||||
// }
|
||||
|
||||
// // After we kill node1 check the data if was replicated in node2
|
||||
// func testRedisSentinelGetAttrAfterFailover(t *testing.T) {
|
||||
// alsPrf := &engine.AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ApierTest",
|
||||
// FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*opts.*context:*sessions|*cdrs"},
|
||||
// Attributes: []*engine.Attribute{
|
||||
// {
|
||||
// Path: utils.MetaReq + utils.NestingSep + utils.Subject,
|
||||
// Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
|
||||
// },
|
||||
// },
|
||||
// Weight: 20,
|
||||
// }
|
||||
// alsPrf.Compile()
|
||||
// var reply *engine.AttributeProfile
|
||||
// if err := sentinelRPC.Call(utils.APIerSv1GetAttributeProfile,
|
||||
// &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// reply.Compile()
|
||||
// if !reflect.DeepEqual(alsPrf, reply) {
|
||||
// t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func testRedisSentinelKillEngine(t *testing.T) {
|
||||
// if err := exec.Command("pkill", "redis-server").Run(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if err := exec.Command("pkill", "redis-sentinel").Run(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if err := exec.Command("pkill", "redis-ser").Run(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if err := exec.Command("pkill", "redis-sen").Run(); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// if err := engine.KillEngine(2000); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user