Files
cgrates/services/sessions_it_test.go
ionutboangiu cb7ea790de Update rpcclient library to latest version
Replace all instances of rpcclient.ClientConnector with birpc.ClientConnector.

Pass context, maxReconnectInterval, delayFunc and birpcClient to rpcclient
constructors.

Remove redundant time.Duration conversions (e.g. time.Duration(1*time.Second)
now becomes time.Second.

Add context where needed (context.Background() for tests, context.TODO()
for places where it should be passed from somewhere else).

Implement that functionality of the SessionSv1.Sleep call, in sessions/sessions
instead of apier/v1.

Make changes in utils/server.go (replacing the old rpc2 library with github.com/cgrates/birpc).

Change the way we register birpc methods for sessions in services, using a helper function
defined in engine/libengine.go.
2023-05-03 10:02:15 +02:00

123 lines
4.2 KiB
Go

//go:build integration
// +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/birpc"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
)
func TestSessionSReload(t *testing.T) {
cfg, err := config.NewDefaultCGRConfig()
if err != nil {
t.Fatal(err)
}
cfg.ChargerSCfg().Enabled = true
cfg.RalsCfg().Enabled = true
cfg.CdrsCfg().Enabled = true
utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
utils.Logger.SetLogLevel(7)
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
engineShutdown := make(chan bool, 1)
chS := engine.NewCacheS(cfg, nil)
close(chS.GetPrecacheChannel(utils.CacheChargerProfiles))
close(chS.GetPrecacheChannel(utils.CacheChargerFilterIndexes))
close(chS.GetPrecacheChannel(utils.CacheDestinations))
close(chS.GetPrecacheChannel(utils.CacheReverseDestinations))
close(chS.GetPrecacheChannel(utils.CacheRatingPlans))
close(chS.GetPrecacheChannel(utils.CacheRatingProfiles))
close(chS.GetPrecacheChannel(utils.CacheActions))
close(chS.GetPrecacheChannel(utils.CacheActionPlans))
close(chS.GetPrecacheChannel(utils.CacheAccountActionPlans))
close(chS.GetPrecacheChannel(utils.CacheActionTriggers))
close(chS.GetPrecacheChannel(utils.CacheSharedGroups))
close(chS.GetPrecacheChannel(utils.CacheTimings))
internalChan := make(chan birpc.ClientConnector, 1)
internalChan <- nil
cacheSChan := make(chan birpc.ClientConnector, 1)
cacheSChan <- chS
server := utils.NewServer()
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
db := NewDataDBService(cfg, nil)
cfg.StorDbCfg().Type = utils.MetaInternal
stordb := NewStorDBService(cfg)
chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil)
schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil)
ralS := NewRalService(cfg, chS, server,
make(chan birpc.ClientConnector, 1), make(chan birpc.ClientConnector, 1),
engineShutdown, nil)
cdrS := NewCDRServer(cfg, db, stordb, filterSChan, server,
make(chan birpc.ClientConnector, 1),
nil)
srv := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), engineShutdown, nil)
engine.NewConnManager(cfg, nil)
srvMngr.AddServices(srv, chrS, schS, ralS, cdrS,
NewLoaderService(cfg, db, filterSChan, server, engineShutdown, make(chan birpc.ClientConnector, 1), nil), db, stordb)
if err = srvMngr.StartServices(); err != nil {
t.Error(err)
}
time.Sleep(10 * time.Millisecond)
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
if !db.IsRunning() {
t.Errorf("Expected service to be running")
}
if !stordb.IsRunning() {
t.Errorf("Expected service to be running")
}
var reply string
if err := cfg.V1ReloadConfigFromPath(&config.ConfigReloadWithArgDispatcher{
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
Section: config.SessionSJson,
}, &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")
}
cfg.SessionSCfg().Enabled = false
cfg.GetReloadChan(config.SessionSJson) <- struct{}{}
time.Sleep(10 * time.Millisecond)
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
engineShutdown <- true
}