mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
Integration tests in services
This commit is contained in:
committed by
Dan Christian Bogos
parent
e5f3961a53
commit
a3e77e837a
@@ -1426,7 +1426,8 @@ func (cfg *CGRConfig) reloadSections(sections ...string) {
|
||||
subsystemsThatNeedDataDB := utils.NewStringSet([]string{DATADB_JSN, SCHEDULER_JSN,
|
||||
RALS_JSN, CDRS_JSN, SessionSJson, ATTRIBUTE_JSN,
|
||||
ChargerSCfgJson, RESOURCES_JSON, STATS_JSON, THRESHOLDS_JSON,
|
||||
RouteSJson, LoaderJson, DispatcherSJson, RateSJson, ApierS, AccountSCfgJson})
|
||||
RouteSJson, LoaderJson, DispatcherSJson, RateSJson, ApierS, AccountSCfgJson,
|
||||
ActionSJson})
|
||||
subsystemsThatNeedStorDB := utils.NewStringSet([]string{STORDB_JSN, RALS_JSN, CDRS_JSN, ApierS})
|
||||
needsDataDB := false
|
||||
needsStorDB := false
|
||||
@@ -1519,6 +1520,8 @@ func (cfg *CGRConfig) reloadSections(sections ...string) {
|
||||
cfg.rldChans[DispatcherHJson] <- struct{}{}
|
||||
case AccountSCfgJson:
|
||||
cfg.rldChans[AccountSCfgJson] <- struct{}{}
|
||||
case ActionSJson:
|
||||
cfg.rldChans[ActionSJson] <- struct{}{}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
110
services/actions_it_test.go
Normal file
110
services/actions_it_test.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// +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 (
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/rpcclient"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestActionSReload(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
|
||||
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
|
||||
utils.Logger.SetLogLevel(7)
|
||||
|
||||
shdChan := utils.NewSyncedChan()
|
||||
shdWg := new(sync.WaitGroup)
|
||||
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)
|
||||
srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
|
||||
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)
|
||||
engine.NewConnManager(cfg, nil)
|
||||
srvMngr.AddServices(actS,
|
||||
NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
|
||||
if err := srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if actS.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.ActionSJson,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expecting OK ,received %s", reply)
|
||||
}
|
||||
select {
|
||||
case d := <-actRPC:
|
||||
actRPC <- d
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("It took to long to reload the cache")
|
||||
}
|
||||
if !actS.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := actS.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = actS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
cfg.ActionSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.ActionSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
if actS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
shdChan.CloseOnce()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (db *DataDBService) mandatoryDB() bool {
|
||||
db.cfg.AttributeSCfg().Enabled || db.cfg.ResourceSCfg().Enabled || db.cfg.StatSCfg().Enabled ||
|
||||
db.cfg.ThresholdSCfg().Enabled || db.cfg.RouteSCfg().Enabled || db.cfg.DispatcherSCfg().Enabled ||
|
||||
db.cfg.LoaderCfg().Enabled() || db.cfg.ApierCfg().Enabled || db.cfg.RateSCfg().Enabled ||
|
||||
db.cfg.AccountSCfg().Enabled
|
||||
db.cfg.AccountSCfg().Enabled || db.cfg.ActionSCfg().Enabled
|
||||
}
|
||||
|
||||
// GetDM returns the DataManager
|
||||
|
||||
@@ -249,6 +249,8 @@ func (srvMngr *ServiceManager) handleReload() {
|
||||
go srvMngr.reloadService(utils.GlobalVarS)
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.AccountSCfgJson):
|
||||
go srvMngr.reloadService(utils.AccountS)
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.ActionSJson):
|
||||
go srvMngr.reloadService(utils.ActionS)
|
||||
}
|
||||
// handle RPC server
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user