diff --git a/config/config_test.go b/config/config_test.go index f792f7c2f..65c962382 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -5578,6 +5578,9 @@ func TestV1GetConfigAsJSONCoreS(t *testing.T) { var result string cfgCgr2 := NewDefaultCGRConfig() + for _, section := range sortedCfgSections { + cfgCgr2.rldChans[section] = make(chan struct{}, 1) + } if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: reply, DryRun: true}, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -5585,7 +5588,9 @@ func TestV1GetConfigAsJSONCoreS(t *testing.T) { } else if cgrCfg := NewDefaultCGRConfig(); !reflect.DeepEqual(cgrCfg.CoreSCfg(), cfgCgr2.CoreSCfg()) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(cgrCfg.CoreSCfg()), utils.ToJSON(cfgCgr2.CoreSCfg())) } - + for _, section := range sortedCfgSections { + cfgCgr2.rldChans[section] = make(chan struct{}, 1) + } if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -5605,6 +5610,10 @@ func TestV1GetConfigAsJSONCheckConfigSanity(t *testing.T) { }` expected := ` not enabled but requested by component` cfgCgr2 := NewDefaultCGRConfig() + for _, section := range sortedCfgSections { + cfgCgr2.rldChans[section] = make(chan struct{}, 1) + } + if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: args}, &result); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -5647,6 +5656,9 @@ func TestV1GetConfigAsJSONAllConfig(t *testing.T) { func TestV1ReloadConfigFromJSONEmptyConfig(t *testing.T) { var reply string cgrCfg := NewDefaultCGRConfig() + for _, section := range sortedCfgSections { + cgrCfg.rldChans[section] = make(chan struct{}, 1) + } if err := cgrCfg.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: utils.EmptyString}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -5658,6 +5670,9 @@ func TestV1ReloadConfigFromJSONInvalidSection(t *testing.T) { var reply string expected := "invalid character 'I' looking for beginning of value around line 1 and position 1\n line: \"InvalidSection\"" cgrCfg := NewDefaultCGRConfig() + for _, section := range sortedCfgSections { + cgrCfg.rldChans[section] = make(chan struct{}, 1) + } if err := cgrCfg.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: "InvalidSection"}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -5901,6 +5916,9 @@ func TestReloadSections(t *testing.T) { SessionSJson, AsteriskAgentJSN, FreeSWITCHAgentJSN, KamailioAgentJSN, DA_JSN, RA_JSN, HttpAgentJson, DNSAgentJson, ATTRIBUTE_JSN, ChargerSCfgJson, RESOURCES_JSON, STATS_JSON, THRESHOLDS_JSON, RouteSJson, LoaderJson, DispatcherSJson, ApierS, EEsJson, SIPAgentJson, RateSJson, DispatcherHJson, AnalyzerCfgJson} { + for _, section := range sortedCfgSections { + cfgCgr.rldChans[section] = make(chan struct{}, 1) + } cfgCgr.reloadSections(section) // the chan should be populated if len(cfgCgr.GetReloadChan(section)) != 1 { @@ -5926,6 +5944,9 @@ func TestReloadSections(t *testing.T) { func TestReloadSectionsSpecialCase(t *testing.T) { cgrCfg = NewDefaultCGRConfig() + for _, section := range sortedCfgSections { + cgrCfg.rldChans[section] = make(chan struct{}, 1) + } cgrCfg.reloadSections(RPCConnsJsonName, RALS_JSN) // the chan should be populated diff --git a/services/diameteragent_it_test.go b/services/diameteragent_it_test.go index 9a85e6b88..562a09b20 100644 --- a/services/diameteragent_it_test.go +++ b/services/diameteragent_it_test.go @@ -19,7 +19,20 @@ along with this program. If not, see */ package services -/* +import ( + "path" + "sync" + "testing" + "time" + + "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" + "github.com/cgrates/rpcclient" +) + func TestDiameterAgentReload1(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().Enabled = true @@ -96,42 +109,15 @@ func TestDiameterAgentReload2(t *testing.T) { filterSChan := make(chan *engine.FilterS, 1) filterSChan <- nil shdChan := utils.NewSyncedChan() - shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) cacheSChan := make(chan rpcclient.ClientConnector, 1) cacheSChan <- chS - server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg) - db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), - shdChan, nil, nil, anz, srvDep) srv := NewDiameterAgent(cfg, filterSChan, shdChan, nil, srvDep) - engine.NewConnManager(cfg, nil) - srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) - if err := srvMngr.StartServices(); err != nil { - t.Fatal(err) - } if srv.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", "diamagent_mysql"), - Section: config.DA_JSN, - }, &reply); err != nil { - t.Fatal(err) - } else if reply != utils.OK { - t.Errorf("Expecting OK ,received %s", reply) - } - time.Sleep(10 * time.Millisecond) //need to switch to gorutine - cfg.DiameterAgentCfg().Enabled = false - cfg.GetReloadChan(config.DA_JSN) <- struct{}{} - srv.(*DiameterAgent).stopChan = make(chan struct{}, 1) - srv.(*DiameterAgent).stopChan = make(chan struct{}, 1) srv.Shutdown() if srv.IsRunning() { @@ -168,4 +154,3 @@ func TestDiameterAgentReload3(t *testing.T) { } } -*/ diff --git a/services/ees.go b/services/ees.go index c273d1b33..377401e77 100644 --- a/services/ees.go +++ b/services/ees.go @@ -81,7 +81,7 @@ func (es *EventExporterService) ShouldRun() (should bool) { func (es *EventExporterService) IsRunning() bool { es.RLock() defer es.RUnlock() - return es.eeS != nil + return es != nil && es.eeS != nil } // Reload handles the change of config diff --git a/services/ees_it_test.go b/services/ees_it_test.go index 6b143e083..62579bc08 100644 --- a/services/ees_it_test.go +++ b/services/ees_it_test.go @@ -65,7 +65,8 @@ func TestEventExporterSReload(t *testing.T) { attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - ees := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + ees := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), + server, make(chan rpcclient.ClientConnector, 2), anz, srvDep) srvMngr.AddServices(ees, attrS, NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil {