mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added rates service reload test
This commit is contained in:
committed by
Dan Christian Bogos
parent
16b3bcb53b
commit
04a2a4d02f
@@ -1538,6 +1538,8 @@ func (cfg *CGRConfig) reloadSections(sections ...string) (err error) {
|
||||
cfg.rldChans[EEsJson] <- struct{}{}
|
||||
case SIPAgentJson:
|
||||
cfg.rldChans[SIPAgentJson] <- struct{}{}
|
||||
case RateSJson:
|
||||
cfg.rldChans[RateSJson] <- struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -113,5 +114,12 @@ func (rs *RateService) Start() (err error) {
|
||||
}
|
||||
*/
|
||||
rs.intConnChan <- rs.rateS
|
||||
return rs.rateS.ListenAndServe(rs.exitChan, rs.rldChan)
|
||||
|
||||
go func(rtS *rates.RateS, exitChan chan bool, rldChan chan struct{}) {
|
||||
if err := rtS.ListenAndServe(exitChan, rldChan); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s>", utils.EventExporterS, err.Error()))
|
||||
exitChan <- true
|
||||
}
|
||||
}(rs.rateS, rs.exitChan, rs.rldChan)
|
||||
return
|
||||
}
|
||||
|
||||
77
services/rates_it_test.go
Normal file
77
services/rates_it_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// +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"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/rpcclient"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestRateSReload(t *testing.T) {
|
||||
cfg, err := config.NewDefaultCGRConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
|
||||
utils.Logger.SetLogLevel(7)
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
filterSChan <- nil
|
||||
engineShutdown := make(chan bool, 1)
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
|
||||
db := NewDataDBService(cfg, nil)
|
||||
rS := NewRateService(cfg, filterSChan, server, engineShutdown, make(chan rpcclient.ClientConnector, 1))
|
||||
srvMngr.AddServices(rS,
|
||||
NewLoaderService(cfg, db, filterSChan, server, engineShutdown, make(chan rpcclient.ClientConnector, 1), nil), db)
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
var reply string
|
||||
if err := cfg.V1ReloadConfigFromPath(&config.ConfigReloadWithArgDispatcher{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "rates"),
|
||||
Section: config.RateSJson,
|
||||
}, &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 !rS.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
cfg.RateSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RateSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if rS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
engineShutdown <- true
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (srvMngr *ServiceManager) handleReload() {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.RateSJson):
|
||||
if err = srvMngr.reloadService(config.RateSJson); err != nil {
|
||||
if err = srvMngr.reloadService(utils.RateS); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.RPCConnsJsonName):
|
||||
|
||||
Reference in New Issue
Block a user