Fixed function and test in services

This commit is contained in:
andronache
2021-02-10 12:41:29 +02:00
committed by Dan Christian Bogos
parent adaad39c3b
commit 7f03bafbc9
2 changed files with 20 additions and 3 deletions

View File

@@ -75,11 +75,11 @@ func (fS *FreeswitchAgent) Start() (err error) {
// Reload handles the change of config
func (fS *FreeswitchAgent) Reload() (err error) {
if err = fS.Shutdown(); err != nil {
return
}
fS.Lock()
defer fS.Unlock()
if err = fS.fS.Shutdown(); err != nil {
return
}
fS.fS.Reload()
go func(f *agents.FSsessions) {
if err := fS.fS.Connect(); err != nil {

View File

@@ -26,6 +26,8 @@ import (
"testing"
"time"
"github.com/cgrates/cgrates/agents"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -75,11 +77,26 @@ func TestFreeSwitchAgentReload(t *testing.T) {
} else if reply != utils.OK {
t.Errorf("Expecting OK ,received %s", reply)
}
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
// the engine should be stopped as we could not connect to freeswitch
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
agentCfg := &config.FsAgentCfg{
Enabled: true,
CreateCdr: true,
SubscribePark: true,
EventSocketConns: []*config.FsConnCfg{},
}
srv.(*FreeswitchAgent).fS = agents.NewFSsessions(agentCfg, "", nil)
//srv.(*FreeswitchAgent).fS = new(agents.FSsessions)
err := srv.Reload()
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
time.Sleep(10 * time.Millisecond)
shdChan.CloseOnce()
runtime.Gosched()