Files
cgrates/services/ers_it_test.go
2019-10-28 12:17:15 +01:00

86 lines
2.7 KiB
Go

// +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 (
"os"
"path"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
)
func TestEventReaderSReload(t *testing.T) {
for _, dir := range []string{"/tmp/ers/in", "/tmp/ers/out"} {
if err := os.RemoveAll(dir); err != nil {
t.Fatal("Error removing folder: ", dir, err)
}
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal("Error creating folder: ", dir, err)
}
}
cfg, err := config.NewDefaultCGRConfig()
if err != nil {
t.Fatal(err)
}
utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
utils.Logger.SetLogLevel(7)
cfg.SessionSCfg().Enabled = true
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
engineShutdown := make(chan bool, 1)
server := utils.NewServer()
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
sS := NewSessionService(cfg, nil, server, nil,
nil, nil, nil, nil, nil, nil, nil, nil, engineShutdown)
attrS := NewEventReaderService(cfg, filterSChan, sS.GetIntenternalChan(), nil, engineShutdown)
srvMngr.AddServices(attrS, sS, NewLoaderService(cfg, nil, filterSChan, server, nil, nil, engineShutdown))
if err = srvMngr.StartServices(); err != nil {
t.Error(err)
}
if attrS.IsRunning() {
t.Errorf("Expected service to be down")
}
var reply string
if err := cfg.V1ReloadConfig(&config.ConfigReloadWithArgDispatcher{
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ers_reload", "internal"),
Section: config.ERsJson,
}, &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 !attrS.IsRunning() {
t.Errorf("Expected service to be running")
}
cfg.ERsCfg().Enabled = false
cfg.GetReloadChan(config.ERsJson) <- struct{}{}
time.Sleep(10 * time.Millisecond)
if attrS.IsRunning() {
t.Errorf("Expected service to be down")
}
engineShutdown <- true
}