mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge pull request #2551 from andronache98/master
Cover testing in services
This commit is contained in:
85
services/actions_it_test.go
Normal file
85
services/actions_it_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package services
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/actions"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
//TestNewActionService for cover testing
|
||||
func TestActionSCoverage(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
|
||||
utils.Logger.SetLogLevel(7)
|
||||
shdChan := utils.NewSyncedChan()
|
||||
chS := engine.NewCacheS(cfg, nil, nil)
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
filterSChan <- nil
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionProfiles))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionProfilesFilterIndexes))
|
||||
server := cores.NewServer(nil)
|
||||
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
|
||||
db := NewDataDBService(cfg, nil, srvDep)
|
||||
actRPC := make(chan rpcclient.ClientConnector, 1)
|
||||
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
|
||||
actS := NewActionService(cfg, db,
|
||||
chS, filterSChan, server, actRPC,
|
||||
anz, srvDep)
|
||||
if actS == nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(actS))
|
||||
}
|
||||
actS2 := &ActionService{
|
||||
cfg: cfg,
|
||||
dm: db,
|
||||
cacheS: chS,
|
||||
filterSChan: filterSChan,
|
||||
server: server,
|
||||
rldChan: make(chan struct{}),
|
||||
connChan: actRPC,
|
||||
anz: anz,
|
||||
srvDep: srvDep,
|
||||
}
|
||||
if actS2.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
actS2.acts = actions.NewActionS(cfg, &engine.FilterS{}, &engine.DataManager{})
|
||||
if !actS2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
serviceName := actS2.ServiceName()
|
||||
if !reflect.DeepEqual(serviceName, utils.ActionS) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ActionS, serviceName)
|
||||
}
|
||||
shouldRun := actS2.ShouldRun()
|
||||
if !reflect.DeepEqual(shouldRun, false) {
|
||||
t.Errorf("\nExpecting <false>,\n Received <%+v>", shouldRun)
|
||||
}
|
||||
|
||||
}
|
||||
82
services/analyzers_it_test.go
Normal file
82
services/analyzers_it_test.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package services
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/analyzers"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
//TestNewActionService for cover testing
|
||||
func TestNewAnalyzerCoverage(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
|
||||
utils.Logger.SetLogLevel(7)
|
||||
shdChan := utils.NewSyncedChan()
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
filterSChan <- nil
|
||||
server := cores.NewServer(nil)
|
||||
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
|
||||
connChan := make(chan rpcclient.ClientConnector, 1)
|
||||
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, connChan, srvDep)
|
||||
if anz == nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(anz))
|
||||
}
|
||||
anz2 := &AnalyzerService{
|
||||
connChan: connChan,
|
||||
cfg: cfg,
|
||||
server: server,
|
||||
filterSChan: filterSChan,
|
||||
shdChan: shdChan,
|
||||
srvDep: srvDep,
|
||||
}
|
||||
if anz2.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
anz2.anz = &analyzers.AnalyzerService{}
|
||||
if !anz2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := anz2.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
serviceName := anz2.ServiceName()
|
||||
if !reflect.DeepEqual(serviceName, utils.AnalyzerS) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.AnalyzerS, serviceName)
|
||||
}
|
||||
shouldRun := anz2.ShouldRun()
|
||||
if !reflect.DeepEqual(shouldRun, false) {
|
||||
t.Errorf("\nExpecting <false>,\n Received <%+v>", shouldRun)
|
||||
}
|
||||
getAnalyzerS := anz2.GetAnalyzerS()
|
||||
if !reflect.DeepEqual(anz2.anz, getAnalyzerS) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(anz2.anz), utils.ToJSON(getAnalyzerS))
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,13 @@ package services
|
||||
|
||||
import (
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -102,6 +105,27 @@ func TestApiersReload(t *testing.T) {
|
||||
if !stordb.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := apiSv1.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err2 := apiSv2.Start()
|
||||
if err2 == nil || err2 != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err2)
|
||||
}
|
||||
err = apiSv1.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
err2 = apiSv2.Reload()
|
||||
if err2 != nil {
|
||||
t.Errorf("\nExpecting <nil>,\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))
|
||||
}
|
||||
cfg.ApierCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.ApierS) <- struct{}{}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
@@ -78,6 +78,10 @@ func TestAsteriskAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
cfg.AsteriskAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.AsteriskAgentJSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -65,7 +65,7 @@ type AttributeService struct {
|
||||
srvDep map[string]*sync.WaitGroup
|
||||
}
|
||||
|
||||
// Start should handle the sercive start
|
||||
// Start should handle the service start
|
||||
func (attrS *AttributeService) Start() (err error) {
|
||||
if attrS.IsRunning() {
|
||||
return utils.ErrServiceAlreadyRunning
|
||||
|
||||
@@ -90,12 +90,23 @@ func TestAttributeSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := attrS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = attrS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.AttributeSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.ATTRIBUTE_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
if attrS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
shdChan.CloseOnce()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ func TestCdrsReload(t *testing.T) {
|
||||
if stordb.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
cfg.RalsCfg().Enabled = true
|
||||
var reply string
|
||||
if err := cfg.V1ReloadConfig(&config.ReloadArgs{
|
||||
@@ -115,6 +116,14 @@ func TestCdrsReload(t *testing.T) {
|
||||
if !stordb.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := cdrS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = cdrS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.CdrsCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.CDRS_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -85,6 +85,14 @@ func TestChargerSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := chrS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = chrS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.ChargerSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.ChargerSCfgJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
20
services/cores_it_test.go
Normal file
20
services/cores_it_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// +build integration
|
||||
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package services
|
||||
@@ -78,6 +78,14 @@ func TestDiameterAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.DiameterAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.DA_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -88,6 +88,14 @@ func TestDispatcherSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.DispatcherSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.DispatcherSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -78,6 +78,14 @@ func TestDNSAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.DNSAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.DNSAgentJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -96,6 +96,14 @@ func TestEventExporterSReload(t *testing.T) {
|
||||
if !ees.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := ees.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = ees.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.EEsCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.EEsJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -82,6 +82,14 @@ func TestEventReaderSReload(t *testing.T) {
|
||||
if !attrS.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := attrS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = attrS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.ERsCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.ERsJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -76,6 +76,7 @@ func TestKamailioAgentReload(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expecting OK ,received %s", reply)
|
||||
}
|
||||
|
||||
runtime.Gosched()
|
||||
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
|
||||
// the engine should be stoped as we could not connect to kamailio
|
||||
|
||||
@@ -78,6 +78,14 @@ func TestRadiusAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.RadiusAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RA_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -110,13 +110,20 @@ func TestRalsReload(t *testing.T) {
|
||||
if !stordb.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := ralS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = ralS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.RalsCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RALS_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if ralS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
if resp := ralS.GetResponder(); resp.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ func TestRateSReload(t *testing.T) {
|
||||
if !rS.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := rS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = rS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.RateSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RateSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -87,6 +87,14 @@ func TestResourceSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := reS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = reS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.ResourceSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RESOURCES_JSON) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -85,6 +85,14 @@ func TestSupplierSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := supS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = supS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.RouteSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RouteSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -21,6 +21,7 @@ package services
|
||||
|
||||
import (
|
||||
"path"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -78,6 +79,18 @@ func TestSchedulerSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := schS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = schS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
getScheduler := schS.GetScheduler()
|
||||
if !reflect.DeepEqual(schS.schS, getScheduler) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(schS.schS), utils.ToJSON(getScheduler))
|
||||
}
|
||||
cfg.SchedulerCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.SCHEDULER_JSN) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -113,6 +113,14 @@ func TestSessionSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.SessionSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.SessionSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -78,6 +78,10 @@ func TestSIPAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := srv.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <err>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.SIPAgentCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.SIPAgentJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -87,6 +87,14 @@ func TestStatSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := sS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = sS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.StatSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.STATS_JSON) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -81,6 +81,14 @@ func TestThresholdSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := tS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = tS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.ThresholdSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.THRESHOLDS_JSON) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -304,7 +304,7 @@ func (srvMngr *ServiceManager) ShutdownServices() {
|
||||
|
||||
// Service interface that describes what functions should a service implement
|
||||
type Service interface {
|
||||
// Start should handle the sercive start
|
||||
// Start should handle the service start
|
||||
Start() error
|
||||
// Reload handles the change of config
|
||||
Reload() error
|
||||
|
||||
Reference in New Issue
Block a user