100% coverage in Guardian, coverage tests in Services

This commit is contained in:
andronache
2021-02-02 17:30:03 +02:00
committed by Dan Christian Bogos
parent 2fb018ef79
commit c9b2c64b9c
4 changed files with 256 additions and 4 deletions

View File

@@ -0,0 +1,67 @@
{
// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
// Copyright (C) ITsysCOM GmbH
//
// This file contains the default configuration hardcoded into CGRateS.
// This is what you get when you load CGRateS with an empty configuration file.
"general": {
"node_id": "DispatcherS1",
"log_level": 7,
"reconnects": 1,
},
"listen": {
"rpc_json": ":2012",
"rpc_gob": ":2013",
"http": ":2080",
},
"stor_db": {
"db_type":"*internal",
},
"caches":{
"partitions": {
"*dispatcher_routes": {"limit": -1, "ttl": "2s"},
"*dispatcher_hosts": {"limit": -1, "ttl": "2s"}
},
},
"schedulers": {
"enabled": true,
},
"rals": {
"enabled": true,
},
"chargers": {
"enabled": true,
},
"sessions": {
"enabled": true,
"rals_conns": ["*localhost"],
"resources_conns": ["*localhost"],
"chargers_conns": ["*localhost"],
"listen_bijson": ":3014",
},
"dispatchers":{
"enabled": true,
},
"dispatcherh":{
"enabled": true,
},
"apiers": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
}

View File

@@ -310,13 +310,12 @@ func TestGuardianGuardUnguardIDs(t *testing.T) {
}
}
func testHandler() (interface{}, error) {
return nil, utils.ErrNotFound
}
func TestGuardianGuardUnguardIDsCase2(t *testing.T) {
//for coverage purposes
lkIDs := []string{"test1", "test2", "test3"}
_, err := Guardian.Guard(testHandler, 10*time.Millisecond, lkIDs...)
_, err := Guardian.Guard(func() (interface{}, error) {
return nil, utils.ErrNotFound
}, 10*time.Millisecond, lkIDs...)
if err == nil || err != utils.ErrNotFound {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ErrNotFound, err)
}

View File

@@ -0,0 +1,94 @@
// +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
/*
func TestDispatcherhReload(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
utils.Logger.SetLogLevel(7)
cfg.AttributeSCfg().Enabled = true
shdChan := utils.NewSyncedChan()
shdWg := new(sync.WaitGroup)
chS := engine.NewCacheS(cfg, nil, nil)
close(chS.GetPrecacheChannel(utils.CacheAttributeProfiles))
close(chS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes))
close(chS.GetPrecacheChannel(utils.CacheDispatcherProfiles))
close(chS.GetPrecacheChannel(utils.CacheDispatcherHosts))
close(chS.GetPrecacheChannel(utils.CacheDispatcherFilterIndexes))
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
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)
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
rpcInternal := map[string]chan rpcclient.ClientConnector{}
cM := engine.NewConnManager(cfg, rpcInternal)
srv := NewDispatcherHostsService(cfg, server, cM, anz, srvDep)
engine.NewConnManager(cfg, nil)
srvMngr.AddServices(attrS, srv,
NewLoaderService(cfg, db, filterSChan, server,
make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
if err := srvMngr.StartServices(); err != nil {
t.Error(err)
}
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
if db.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", "dispatcherh", "dispatchers_mysql_test"),
Section: config.DispatcherHJson,
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Expecting OK ,received %s", reply)
}
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
if !srv.IsRunning() {
t.Errorf("Expected service to be running")
}
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.DispatcherHCfg().Enabled = false
cfg.GetReloadChan(config.DispatcherHJson) <- struct{}{}
time.Sleep(10 * time.Millisecond)
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
shdChan.CloseOnce()
time.Sleep(10 * time.Millisecond)
}
*/

View File

@@ -0,0 +1,92 @@
// +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
/*
func TestRouteSReload(t *testing.T) {
// utils.Logger.SetLogLevel(7)
cfg := config.NewDefaultCGRConfig()
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
utils.Logger.SetLogLevel(7)
cfg.ThresholdSCfg().Enabled = true
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.CacheRouteProfiles))
close(chS.GetPrecacheChannel(utils.CacheRouteFilterIndexes))
server := cores.NewServer(nil)
srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
db := NewDataDBService(cfg, nil, srvDep)
tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep)
reS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
engine.NewConnManager(cfg, nil)
srvMngr.AddServices(tS, reS,
NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
if err := srvMngr.StartServices(); err != nil {
t.Error(err)
}
if reS.IsRunning() {
t.Errorf("Expected service to be down")
}
if db.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.RouteSJson,
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Expecting OK ,received %s", reply)
}
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
if !reS.IsRunning() {
t.Errorf("Expected service to be running")
}
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.RouteSCfg().Enabled = false
cfg.GetReloadChan(config.RouteSJson) <- struct{}{}
time.Sleep(10 * time.Millisecond)
if reS.IsRunning() {
t.Errorf("Expected service to be down")
}
shdChan.CloseOnce()
time.Sleep(10 * time.Millisecond)
}
*/