mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Revise usage of httpcfg's transport and fix tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
013a10ad09
commit
b0cac1b6ee
@@ -21,6 +21,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -108,7 +109,8 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) {
|
||||
cacheCfg: &CacheCfg{Partitions: make(map[string]*CacheParamCfg)},
|
||||
listenCfg: new(ListenCfg),
|
||||
httpCfg: &HTTPCfg{
|
||||
ClientOpts: &HTTPClientOpts{},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
},
|
||||
filterSCfg: new(FilterSCfg),
|
||||
cdrsCfg: &CdrsCfg{Opts: &CdrsOpts{
|
||||
|
||||
@@ -1718,21 +1718,21 @@ func TestDfHttpJsonCfg(t *testing.T) {
|
||||
Http_Cdrs: utils.StringPointer("/cdr_http"),
|
||||
Use_basic_auth: utils.BoolPointer(false),
|
||||
Auth_users: utils.MapStringStringPointer(map[string]string{}),
|
||||
Client_opts: map[string]interface{}{
|
||||
utils.HTTPClientSkipTLSVerificationCfg: false,
|
||||
utils.HTTPClientTLSHandshakeTimeoutCfg: "10s",
|
||||
utils.HTTPClientDisableKeepAlivesCfg: false,
|
||||
utils.HTTPClientDisableCompressionCfg: false,
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100.,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2.,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0.,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "90s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0",
|
||||
utils.HTTPClientForceAttemptHTTP2Cfg: true,
|
||||
utils.HTTPClientDialTimeoutCfg: "30s",
|
||||
utils.HTTPClientDialFallbackDelayCfg: "300ms",
|
||||
utils.HTTPClientDialKeepAliveCfg: "30s",
|
||||
Client_opts: &HTTPClientOptsJson{
|
||||
SkipTLSVerification: utils.BoolPointer(false),
|
||||
TLSHandshakeTimeout: utils.StringPointer("10s"),
|
||||
DisableKeepAlives: utils.BoolPointer(false),
|
||||
DisableCompression: utils.BoolPointer(false),
|
||||
MaxIdleConns: utils.IntPointer(100),
|
||||
MaxIdleConnsPerHost: utils.IntPointer(2),
|
||||
MaxConnsPerHost: utils.IntPointer(0),
|
||||
IdleConnTimeout: utils.StringPointer("90s"),
|
||||
ResponseHeaderTimeout: utils.StringPointer("0"),
|
||||
ExpectContinueTimeout: utils.StringPointer("0"),
|
||||
ForceAttemptHTTP2: utils.BoolPointer(true),
|
||||
DialTimeout: utils.StringPointer("30s"),
|
||||
DialFallbackDelay: utils.StringPointer("300ms"),
|
||||
DialKeepAlive: utils.StringPointer("30s"),
|
||||
},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -18,8 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -42,28 +46,35 @@ func TestHTTPCfgloadFromJsonCfg(t *testing.T) {
|
||||
CDRsURL: "/cdr_http",
|
||||
UseBasicAuth: false,
|
||||
AuthUsers: map[string]string{},
|
||||
ClientOpts: map[string]interface{}{
|
||||
utils.HTTPClientSkipTLSVerificationCfg: false,
|
||||
utils.HTTPClientTLSHandshakeTimeoutCfg: "10s",
|
||||
utils.HTTPClientDisableKeepAlivesCfg: false,
|
||||
utils.HTTPClientDisableCompressionCfg: false,
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100.,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2.,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0.,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "90s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0",
|
||||
utils.HTTPClientForceAttemptHTTP2Cfg: true,
|
||||
utils.HTTPClientDialTimeoutCfg: "30s",
|
||||
utils.HTTPClientDialFallbackDelayCfg: "300ms",
|
||||
utils.HTTPClientDialKeepAliveCfg: "30s",
|
||||
ClientOpts: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: false,
|
||||
},
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
DisableKeepAlives: false,
|
||||
DisableCompression: false,
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 2,
|
||||
MaxConnsPerHost: 0,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
ResponseHeaderTimeout: 0,
|
||||
ExpectContinueTimeout: 0,
|
||||
ForceAttemptHTTP2: true,
|
||||
},
|
||||
dialer: &net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
FallbackDelay: 300 * time.Millisecond,
|
||||
KeepAlive: 30 * time.Second,
|
||||
DualStack: true,
|
||||
},
|
||||
}
|
||||
expected.ClientOpts.DialContext = expected.dialer.DialContext
|
||||
cfgJsn := NewDefaultCGRConfig()
|
||||
if err = cfgJsn.httpCfg.loadFromJSONCfg(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, cfgJsn.httpCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(cfgJsn.httpCfg))
|
||||
} else if !HTTPCfgEqual(expected, cfgJsn.httpCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", expected, cfgJsn.httpCfg)
|
||||
}
|
||||
|
||||
cfgJSONStr = nil
|
||||
@@ -89,12 +100,12 @@ func TestHTTPCfgAsMapInterface(t *testing.T) {
|
||||
utils.HTTPClientTLSHandshakeTimeoutCfg: "10s",
|
||||
utils.HTTPClientDisableKeepAlivesCfg: false,
|
||||
utils.HTTPClientDisableCompressionCfg: false,
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100.,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2.,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0.,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "90s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0",
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "1m30s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0s",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0s",
|
||||
utils.HTTPClientForceAttemptHTTP2Cfg: true,
|
||||
utils.HTTPClientDialTimeoutCfg: "30s",
|
||||
utils.HTTPClientDialFallbackDelayCfg: "300ms",
|
||||
@@ -133,12 +144,12 @@ func TestHTTPCfgAsMapInterface1(t *testing.T) {
|
||||
utils.HTTPClientTLSHandshakeTimeoutCfg: "10s",
|
||||
utils.HTTPClientDisableKeepAlivesCfg: false,
|
||||
utils.HTTPClientDisableCompressionCfg: false,
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100.,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2.,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0.,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "90s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0",
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "1m30s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0s",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0s",
|
||||
utils.HTTPClientForceAttemptHTTP2Cfg: true,
|
||||
utils.HTTPClientDialTimeoutCfg: "30s",
|
||||
utils.HTTPClientDialFallbackDelayCfg: "300ms",
|
||||
@@ -148,7 +159,7 @@ func TestHTTPCfgAsMapInterface1(t *testing.T) {
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := cgrCfg.httpCfg.AsMapInterface(""); !reflect.DeepEqual(rcv, eMap) {
|
||||
t.Errorf("Expected %+v, received %+v", eMap, rcv)
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,15 +174,34 @@ func TestHTTPCfgClone(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"user": "pass",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{
|
||||
utils.HTTPClientSkipTLSVerificationCfg: false,
|
||||
ClientOpts: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: false,
|
||||
},
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
DisableKeepAlives: false,
|
||||
DisableCompression: false,
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 2,
|
||||
MaxConnsPerHost: 0,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
ResponseHeaderTimeout: 0,
|
||||
ExpectContinueTimeout: 0,
|
||||
ForceAttemptHTTP2: true,
|
||||
},
|
||||
dialer: &net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
FallbackDelay: 300 * time.Millisecond,
|
||||
KeepAlive: 30 * time.Second,
|
||||
DualStack: true,
|
||||
},
|
||||
}
|
||||
rcv := ban.Clone()
|
||||
if !reflect.DeepEqual(ban, rcv) {
|
||||
t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(ban), utils.ToJSON(rcv))
|
||||
if !HTTPCfgEqual(rcv, ban) {
|
||||
t.Errorf("Expected: %+v\nReceived: %+v", ban, rcv)
|
||||
}
|
||||
if rcv.ClientOpts[utils.HTTPClientSkipTLSVerificationCfg] = ""; ban.ClientOpts[utils.HTTPClientSkipTLSVerificationCfg] != false {
|
||||
if rcv.ClientOpts.MaxIdleConns = 50; ban.ClientOpts.MaxIdleConns != 100 {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.AuthUsers["user"] = ""; ban.AuthUsers["user"] != "pass" {
|
||||
@@ -192,7 +222,8 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"User1": "passUser1",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
}
|
||||
|
||||
v2 := &HTTPCfg{
|
||||
@@ -205,9 +236,10 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"User2": "passUser2",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{
|
||||
"C_OPT1": "opt",
|
||||
ClientOpts: &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
},
|
||||
dialer: &net.Dialer{},
|
||||
}
|
||||
|
||||
expected := &HTTPJsonCfg{
|
||||
@@ -220,8 +252,8 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
Auth_users: &map[string]string{
|
||||
"User2": "passUser2",
|
||||
},
|
||||
Client_opts: map[string]interface{}{
|
||||
"C_OPT1": "opt",
|
||||
Client_opts: &HTTPClientOptsJson{
|
||||
MaxIdleConns: utils.IntPointer(100),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -232,7 +264,7 @@ func TestDiffHTTPJsonCfg(t *testing.T) {
|
||||
|
||||
v1 = v2
|
||||
expected = &HTTPJsonCfg{
|
||||
Client_opts: map[string]interface{}{},
|
||||
Client_opts: &HTTPClientOptsJson{},
|
||||
}
|
||||
rcv = diffHTTPJsonCfg(d, v1, v2)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
@@ -252,7 +284,8 @@ func TestHttpCfgCloneSection(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"User1": "passUser1",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
}
|
||||
|
||||
exp := &HTTPCfg{
|
||||
@@ -265,7 +298,8 @@ func TestHttpCfgCloneSection(t *testing.T) {
|
||||
AuthUsers: map[string]string{
|
||||
"User1": "passUser1",
|
||||
},
|
||||
ClientOpts: map[string]interface{}{},
|
||||
ClientOpts: &http.Transport{},
|
||||
dialer: &net.Dialer{},
|
||||
}
|
||||
|
||||
rcv := httpCfg.CloneSection()
|
||||
|
||||
@@ -222,7 +222,7 @@ func TestSessionSCfgloadFromJsonCfgCase13(t *testing.T) {
|
||||
cfgJSON.Opts.DebitInterval = nil
|
||||
|
||||
/////
|
||||
cfgJSON.Opts.LastUsage = []*utils.DynamicStringOpt{
|
||||
cfgJSON.Opts.TTLLastUsage = []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: "1c",
|
||||
@@ -231,10 +231,10 @@ func TestSessionSCfgloadFromJsonCfgCase13(t *testing.T) {
|
||||
if err = jsonCfg.sessionSCfg.loadFromJSONCfg(cfgJSON); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v \n but received \n %v", errExpect, err.Error())
|
||||
}
|
||||
cfgJSON.Opts.LastUsage = nil
|
||||
cfgJSON.Opts.TTLLastUsage = nil
|
||||
|
||||
/////
|
||||
cfgJSON.Opts.LastUsed = []*utils.DynamicStringOpt{
|
||||
cfgJSON.Opts.TTLLastUsed = []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: "1c",
|
||||
@@ -243,10 +243,10 @@ func TestSessionSCfgloadFromJsonCfgCase13(t *testing.T) {
|
||||
if err = jsonCfg.sessionSCfg.loadFromJSONCfg(cfgJSON); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v \n but received \n %v", errExpect, err.Error())
|
||||
}
|
||||
cfgJSON.Opts.LastUsed = nil
|
||||
cfgJSON.Opts.TTLLastUsed = nil
|
||||
|
||||
/////
|
||||
cfgJSON.Opts.Usage = []*utils.DynamicStringOpt{
|
||||
cfgJSON.Opts.TTLUsage = []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: "1c",
|
||||
@@ -255,10 +255,10 @@ func TestSessionSCfgloadFromJsonCfgCase13(t *testing.T) {
|
||||
if err = jsonCfg.sessionSCfg.loadFromJSONCfg(cfgJSON); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v \n but received \n %v", errExpect, err.Error())
|
||||
}
|
||||
cfgJSON.Opts.Usage = nil
|
||||
cfgJSON.Opts.TTLUsage = nil
|
||||
|
||||
/////
|
||||
cfgJSON.Opts.MaxDelay = []*utils.DynamicStringOpt{
|
||||
cfgJSON.Opts.TTLMaxDelay = []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: "1c",
|
||||
@@ -267,7 +267,7 @@ func TestSessionSCfgloadFromJsonCfgCase13(t *testing.T) {
|
||||
if err = jsonCfg.sessionSCfg.loadFromJSONCfg(cfgJSON); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v \n but received \n %v", errExpect, err.Error())
|
||||
}
|
||||
cfgJSON.Opts.MaxDelay = nil
|
||||
cfgJSON.Opts.TTLMaxDelay = nil
|
||||
}
|
||||
|
||||
func TestSessionSCfgloadFromJsonCfgCase2(t *testing.T) {
|
||||
@@ -2072,13 +2072,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: false,
|
||||
},
|
||||
},
|
||||
LastUsage: []*utils.DynamicDurationPointerOpt{
|
||||
TTLLastUsage: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: utils.DurationPointer(5 * time.Second),
|
||||
},
|
||||
},
|
||||
LastUsed: []*utils.DynamicDurationPointerOpt{
|
||||
TTLLastUsed: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: utils.DurationPointer(5 * time.Second),
|
||||
@@ -2090,13 +2090,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
MaxDelay: []*utils.DynamicDurationOpt{
|
||||
TTLMaxDelay: []*utils.DynamicDurationOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicDurationPointerOpt{
|
||||
TTLUsage: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: utils.DurationPointer(5 * time.Second),
|
||||
@@ -2261,13 +2261,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
LastUsage: []*utils.DynamicDurationPointerOpt{
|
||||
TTLLastUsage: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: utils.DurationPointer(6 * time.Second),
|
||||
},
|
||||
},
|
||||
LastUsed: []*utils.DynamicDurationPointerOpt{
|
||||
TTLLastUsed: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: utils.DurationPointer(6 * time.Second),
|
||||
@@ -2279,13 +2279,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: 4 * time.Second,
|
||||
},
|
||||
},
|
||||
MaxDelay: []*utils.DynamicDurationOpt{
|
||||
TTLMaxDelay: []*utils.DynamicDurationOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: 4 * time.Second,
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicDurationPointerOpt{
|
||||
TTLUsage: []*utils.DynamicDurationPointerOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: utils.DurationPointer(4 * time.Second),
|
||||
@@ -2450,13 +2450,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
LastUsage: []*utils.DynamicStringOpt{
|
||||
TTLLastUsage: []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: "6s",
|
||||
},
|
||||
},
|
||||
LastUsed: []*utils.DynamicStringOpt{
|
||||
TTLLastUsed: []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: "6s",
|
||||
@@ -2468,13 +2468,13 @@ func TestDiffSessionsOptsJsonCfg(t *testing.T) {
|
||||
Value: "4s",
|
||||
},
|
||||
},
|
||||
MaxDelay: []*utils.DynamicStringOpt{
|
||||
TTLMaxDelay: []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: "4s",
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicStringOpt{
|
||||
TTLUsage: []*utils.DynamicStringOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: "4s",
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
|
||||
// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
// Copyright (C) ITsysCOM GmbH
|
||||
|
||||
"general": {
|
||||
"log_level": 7,
|
||||
"node_id":"CGRFreeswitch",
|
||||
},
|
||||
|
||||
|
||||
"listen": {
|
||||
"rpc_json": ":2012",
|
||||
"rpc_gob": ":2013",
|
||||
"http": ":2080",
|
||||
},
|
||||
|
||||
|
||||
"stor_db": {
|
||||
"db_password": "CGRateS.org",
|
||||
},
|
||||
|
||||
|
||||
"schedulers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"rals": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"chargers_conns": ["*localhost"],
|
||||
"rals_conns": ["*localhost"],
|
||||
"sessions_cost_retries": 5,
|
||||
},
|
||||
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
"rals_conns": ["*localhost"],
|
||||
"cdrs_conns": ["*localhost"],
|
||||
"chargers_conns": ["*localhost"],
|
||||
"debit_interval": "5s",
|
||||
"channel_sync_interval":"7s",
|
||||
},
|
||||
|
||||
|
||||
"freeswitch_agent": {
|
||||
"enabled": true,
|
||||
"event_socket_conns":[
|
||||
{"address": "127.0.0.1:8021", "password": "ClueCon", "reconnects": -1,"alias":""}
|
||||
],
|
||||
"sessions_conns": ["birpc_localhost"],
|
||||
"create_cdr": true
|
||||
},
|
||||
|
||||
"rpc_conns": {
|
||||
"birpc_localhost": {
|
||||
"conns": [{"address": "127.0.0.1:2014", "transport":"*birpc_json"}],
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
"apiers": {
|
||||
"enabled": true,
|
||||
"scheduler_conns": ["*localhost"],
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
httpPstrTransport = config.CgrConfig().HTTPCfg().ClientOpts.Transport
|
||||
httpPstrTransport = config.CgrConfig().HTTPCfg().ClientOpts
|
||||
}
|
||||
|
||||
// SetConnManager is the exported method to set the connectionManager used when operate on an account.
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
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 engine
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestNewHTTPTransport(t *testing.T) {
|
||||
opts := map[string]interface{}{
|
||||
utils.HTTPClientSkipTLSVerificationCfg: false,
|
||||
utils.HTTPClientTLSHandshakeTimeoutCfg: "10s",
|
||||
utils.HTTPClientDisableKeepAlivesCfg: false,
|
||||
utils.HTTPClientDisableCompressionCfg: false,
|
||||
utils.HTTPClientMaxIdleConnsCfg: 100.,
|
||||
utils.HTTPClientMaxIdleConnsPerHostCfg: 2.,
|
||||
utils.HTTPClientMaxConnsPerHostCfg: 0.,
|
||||
utils.HTTPClientIdleConnTimeoutCfg: "90s",
|
||||
utils.HTTPClientResponseHeaderTimeoutCfg: "0",
|
||||
utils.HTTPClientExpectContinueTimeoutCfg: "0",
|
||||
utils.HTTPClientForceAttemptHTTP2Cfg: true,
|
||||
utils.HTTPClientDialTimeoutCfg: "30s",
|
||||
utils.HTTPClientDialFallbackDelayCfg: "300ms",
|
||||
utils.HTTPClientDialKeepAliveCfg: "30s",
|
||||
}
|
||||
|
||||
expDialer := &net.Dialer{
|
||||
DualStack: true,
|
||||
Timeout: 30 * time.Second,
|
||||
FallbackDelay: 300 * time.Millisecond,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}
|
||||
if dial, err := newDialer(opts); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !(expDialer != nil && dial != nil &&
|
||||
expDialer.DualStack == dial.DualStack &&
|
||||
expDialer.Timeout == dial.Timeout &&
|
||||
expDialer.FallbackDelay == dial.FallbackDelay &&
|
||||
expDialer.KeepAlive == dial.KeepAlive) {
|
||||
t.Errorf("Expected %+v, received %+v", expDialer, dial)
|
||||
}
|
||||
expTransport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 2,
|
||||
MaxConnsPerHost: 0,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
ForceAttemptHTTP2: true,
|
||||
}
|
||||
if trsp, err := NewHTTPTransport(opts); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !(expTransport != nil && trsp != nil && // the dial options are not included
|
||||
expTransport.TLSClientConfig.InsecureSkipVerify == trsp.TLSClientConfig.InsecureSkipVerify &&
|
||||
expTransport.TLSHandshakeTimeout == trsp.TLSHandshakeTimeout &&
|
||||
expTransport.DisableKeepAlives == trsp.DisableKeepAlives &&
|
||||
expTransport.DisableCompression == trsp.DisableCompression &&
|
||||
expTransport.MaxIdleConns == trsp.MaxIdleConns &&
|
||||
expTransport.MaxIdleConnsPerHost == trsp.MaxIdleConnsPerHost &&
|
||||
expTransport.MaxConnsPerHost == trsp.MaxConnsPerHost &&
|
||||
expTransport.IdleConnTimeout == trsp.IdleConnTimeout &&
|
||||
expTransport.ResponseHeaderTimeout == trsp.ResponseHeaderTimeout &&
|
||||
expTransport.ExpectContinueTimeout == trsp.ExpectContinueTimeout &&
|
||||
expTransport.ForceAttemptHTTP2 == trsp.ForceAttemptHTTP2) {
|
||||
t.Errorf("Expected %+v, received %+v", expTransport, trsp)
|
||||
}
|
||||
|
||||
opts[utils.HTTPClientDialKeepAliveCfg] = "30as"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientDialFallbackDelayCfg] = "300ams"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientDialTimeoutCfg] = "30as"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientForceAttemptHTTP2Cfg] = "string"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientExpectContinueTimeoutCfg] = "0a"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientResponseHeaderTimeoutCfg] = "0a"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientIdleConnTimeoutCfg] = "90as"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientMaxConnsPerHostCfg] = "not a number"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientMaxIdleConnsPerHostCfg] = "not a number"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientMaxIdleConnsCfg] = "not a number"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientDisableCompressionCfg] = "string"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientDisableKeepAlivesCfg] = "string"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientTLSHandshakeTimeoutCfg] = "10as"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
opts[utils.HTTPClientSkipTLSVerificationCfg] = "string"
|
||||
if _, err := NewHTTPTransport(opts); err == nil {
|
||||
t.Error("Expected error but the transport was builded succesfully")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetHTTPPstrTransport(t *testing.T) {
|
||||
tmp := httpPstrTransport
|
||||
SetHTTPPstrTransport(nil)
|
||||
if httpPstrTransport != nil {
|
||||
t.Error("Expected the transport to be nil", httpPstrTransport)
|
||||
}
|
||||
httpPstrTransport = tmp
|
||||
}
|
||||
@@ -48,13 +48,13 @@ type GlobalVarS struct {
|
||||
// Start should handle the sercive start
|
||||
func (gv *GlobalVarS) Start(*context.Context, context.CancelFunc) error {
|
||||
ees.SetFailedPostCacheTTL(gv.cfg.GeneralCfg().FailedPostsTTL)
|
||||
engine.SetHTTPPstrTransport(gv.cfg.HTTPCfg().ClientOpts.Transport)
|
||||
engine.SetHTTPPstrTransport(gv.cfg.HTTPCfg().ClientOpts)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reload handles the change of config
|
||||
func (gv *GlobalVarS) Reload(*context.Context, context.CancelFunc) error {
|
||||
engine.SetHTTPPstrTransport(gv.cfg.HTTPCfg().ClientOpts.Transport)
|
||||
engine.SetHTTPPstrTransport(gv.cfg.HTTPCfg().ClientOpts)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user