Files
cgrates/cores/server_test.go
ionutboangiu 958aa267cf Refactor HTTP profiling and flag handling
- hardcode the base path for profiling endpoints to '/debug/pprof/'
- change profiling flag 'httprof_path' to boolean 'http_pprof'
  (because of the above)
- remove redundant profiling endpoint registrations (handled by pprof.Index)
- move profiling registration log after actual registration
- make profiling registration log more descriptive
- use utils.Logger instead of log.Print for the log mentioned above
- refactor flags test into a table test (adding also verification for default
  flag values)
- change 'scheduledShutdown' flag type from string to time.Duration (to avoid
  unnecessary time parsing)
- revise flags usage descriptions
- rename flag 'singlecpu' to 'singleCPU'
- switch to 'ExitOnError' for flag parsing to simplify error handling and
  automatically handle 'ErrHelp' by exiting with status 0 when help is
  requested and status 2 for other parsing errors. Before the following error
  log would have been received:
  '<InitS> error received: <flag: help requested>, exiting!'
- update cgr-engine documentation
2024-08-02 09:35:36 +02:00

106 lines
2.7 KiB
Go

/*
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 cores
import (
"io"
"log"
"net/http"
"os"
"reflect"
"testing"
"github.com/cgrates/cgrates/analyzers"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func TestNewServer(t *testing.T) {
cfgDflt := config.NewDefaultCGRConfig()
cfgDflt.CoreSCfg().CapsStatsInterval = 1
caps := engine.NewCaps(0, utils.MetaBusy)
expected := &Server{
httpMux: http.NewServeMux(),
httpsMux: http.NewServeMux(),
caps: caps,
}
rcv := NewServer(caps)
rcv.stopBiRPCServer = nil
rcv.rpcSrv = nil
rcv.birpcSrv = nil
if !reflect.DeepEqual(expected, rcv) {
t.Errorf("\nExpected %+v,\nreceived %+v", expected, rcv)
}
cfgDflt.AnalyzerSCfg().DBPath = "/tmp/analyzers"
analz, err := analyzers.NewAnalyzerService(cfgDflt)
if err != nil {
t.Error(err)
}
expected.anz = analz
if rcv.SetAnalyzer(analz); !reflect.DeepEqual(rcv, expected) {
t.Errorf("Expected %+v, received %+v", expected, rcv)
}
}
func TestRegisterHttpFunc(t *testing.T) {
log.SetOutput(io.Discard)
cfgDflt := config.NewDefaultCGRConfig()
cfgDflt.CoreSCfg().CapsStatsInterval = 1
caps := engine.NewCaps(0, utils.MetaBusy)
rcv := NewServer(caps)
cfgDflt.AnalyzerSCfg().DBPath = "/tmp/analyzers"
if err := os.RemoveAll(cfgDflt.AnalyzerSCfg().DBPath); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(cfgDflt.AnalyzerSCfg().DBPath, 0700); err != nil {
t.Fatal(err)
}
analz, err := analyzers.NewAnalyzerService(cfgDflt)
if err != nil {
t.Error(err)
}
rcv.SetAnalyzer(analz)
handler := func(http.ResponseWriter, *http.Request) {}
rcv.RegisterHttpFunc("/home", handler)
rcv.RpcRegisterName(utils.EmptyString, handler)
if err := os.RemoveAll(cfgDflt.AnalyzerSCfg().DBPath); err != nil {
t.Fatal(err)
}
rcv.StopBiRPC()
}
func TestRegisterProfiler(t *testing.T) {
cfgDflt := config.NewDefaultCGRConfig()
cfgDflt.CoreSCfg().CapsStatsInterval = 1
caps := engine.NewCaps(0, utils.MetaBusy)
rcv := NewServer(caps)
rcv.RegisterProfiler()
rcv.StopBiRPC()
}