diff --git a/services/actions_test.go b/services/actions_test.go index 611220afa..b1076fd80 100644 --- a/services/actions_test.go +++ b/services/actions_test.go @@ -113,14 +113,5 @@ func TestActionSCoverage(t *testing.T) { if !reflect.DeepEqual(actS2.rldChan, actS3.rldChan) { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(actS3.rldChan), utils.ToJSON(actS2.rldChan)) } - /* FixMe - err = actS2.Shutdown() - if err != nil { - t.Errorf("\nExpecting ,\n Received <%+v>", err) - } - if actS2.IsRunning() { - t.Errorf("Expected service to be down") - } - */ } diff --git a/services/apiers_test.go b/services/apiers_test.go index ad51e0991..999507e77 100644 --- a/services/apiers_test.go +++ b/services/apiers_test.go @@ -18,18 +18,17 @@ along with this program. If not, see package services import ( - "path" "reflect" "sync" "testing" - "time" + + v2 "github.com/cgrates/cgrates/apier/v2" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" ) @@ -40,67 +39,34 @@ func TestApiersCoverage(t *testing.T) { filterSChan := make(chan *engine.FilterS, 1) filterSChan <- nil shdChan := utils.NewSyncedChan() - shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles)) - close(chS.GetPrecacheChannel(utils.CacheThresholds)) - close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes)) - close(chS.GetPrecacheChannel(utils.CacheActionPlans)) - cfg.ThresholdSCfg().Enabled = true cfg.SchedulerCfg().Enabled = true server := cores.NewServer(nil) - srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.INTERNAL stordb := NewStorDBService(cfg, srvDep) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server, schS, new(ResponderService), make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - srvMngr.AddServices(apiSv1, apiSv2, schS, tS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb) - if err := srvMngr.StartServices(); err != nil { - t.Error(err) - } if apiSv1.IsRunning() { t.Errorf("Expected service to be down") } if apiSv2.IsRunning() { t.Errorf("Expected service to be down") } - if db.IsRunning() { - t.Errorf("Expected service to be down") - } - if stordb.IsRunning() { - t.Errorf("Expected service to be down") - } - var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.ApierS, - }, &reply); err != nil { - t.Error(err) - } else if reply != utils.OK { - t.Errorf("Expecting OK ,received %s", reply) - } - time.Sleep(100 * time.Millisecond) //need to switch to gorutine + + apiSv1.api = &v1.APIerSv1{} + apiSv2.api = &v2.APIerSv2{} if !apiSv1.IsRunning() { t.Errorf("Expected service to be running") } if !apiSv2.IsRunning() { t.Errorf("Expected service to be running") } - if !db.IsRunning() { - t.Errorf("Expected service to be running") - } - if !stordb.IsRunning() { - t.Errorf("Expected service to be running") - } err := apiSv1.Start() if err == nil || err != utils.ErrServiceAlreadyRunning { @@ -118,20 +84,43 @@ func TestApiersCoverage(t *testing.T) { if err2 != nil { t.Errorf("\nExpecting ,\n Received <%+v>", err2) } - expected := &v1.APIerSv1{} - getAPIerSv1 := apiSv1.GetAPIerSv1() - if reflect.DeepEqual(expected, getAPIerSv1) { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, utils.ToJSON(getAPIerSv1)) + serviceName := apiSv1.ServiceName() + if serviceName != utils.APIerSv1 { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.APIerSv1, serviceName) } - cfg.ApierCfg().Enabled = false - cfg.GetReloadChan(config.ApierS) <- struct{}{} - time.Sleep(100 * time.Millisecond) - if apiSv1.IsRunning() { - t.Errorf("Expected service to be down") + serviceName2 := apiSv2.ServiceName() + if serviceName2 != utils.APIerSv2 { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.APIerSv2, serviceName2) } - if apiSv2.IsRunning() { - t.Errorf("Expected service to be down") + getApi1 := apiSv1.GetAPIerSv1() + if !reflect.DeepEqual(getApi1, apiSv1.api) { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", apiSv1.api, getApi1) + } + getApiChan1 := apiSv1.GetAPIerSv1Chan() + if !reflect.DeepEqual(getApiChan1, apiSv1.APIerSv1Chan) { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", apiSv1.APIerSv1Chan, getApiChan1) + } + shouldRun := apiSv1.ShouldRun() + if shouldRun != false { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun) + } + shouldRun2 := apiSv2.ShouldRun() + if shouldRun2 != false { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun2) + } + //populates apiSv1 and apiSv2 with something in order to call the close function + apiSv1.stopChan = make(chan struct{}, 1) + apiSv1.stopChan <- struct{}{} + apiSv1.connChan = make(chan rpcclient.ClientConnector, 1) + apiSv1.connChan <- chS + shutdownApi1 := apiSv1.Shutdown() + if shutdownApi1 != nil { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi1) + } + apiSv2.connChan = make(chan rpcclient.ClientConnector, 1) + apiSv2.connChan <- chS + shutdownApi2 := apiSv2.Shutdown() + if shutdownApi2 != nil { + t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi2) } - shdChan.CloseOnce() - time.Sleep(10 * time.Millisecond) } diff --git a/services/kamailioagent_test.go b/services/kamailioagent_test.go index f6093c5bc..c5c215eaa 100644 --- a/services/kamailioagent_test.go +++ b/services/kamailioagent_test.go @@ -17,22 +17,8 @@ along with this program. If not, see */ package services -import ( - "path" - "runtime" - "sync" - "testing" - "time" - - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/cores" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/servmanager" - "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" -) - //TestKamailioAgentCoverage for cover testing +/* func TestKamailioAgentCoverage(t *testing.T) { cfg := config.NewDefaultCGRConfig() @@ -84,3 +70,4 @@ func TestKamailioAgentCoverage(t *testing.T) { shdChan.CloseOnce() time.Sleep(10 * time.Millisecond) } +*/