Skip to content

Commit

Permalink
[FAB-8711] update timeout config labels
Browse files Browse the repository at this point in the history
Change-Id: I1758d27a1bcfe1881c2192ebbf6e21cf4c475796
Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Mar 7, 2018
1 parent f8ea53c commit 9394d3c
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 40 deletions.
6 changes: 6 additions & 0 deletions pkg/client/resmgmt/testdata/ccproposal_test.yaml
Expand Up @@ -40,6 +40,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 30s
cache:
connectionIdle: 30s

# Needed to load users crypto keys and certs.
cryptoconfig:
Expand Down
8 changes: 6 additions & 2 deletions pkg/client/resmgmt/testdata/event_source_missing_test.yaml
Expand Up @@ -28,8 +28,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 30s
discovery:
greylistExpiry: 5s
eventService:
Expand All @@ -40,6 +38,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 30s
cache:
connectionIdle: 30s

# Needed to load users crypto keys and certs.
cryptoconfig:
Expand Down
22 changes: 11 additions & 11 deletions pkg/core/config/config.go
Expand Up @@ -447,30 +447,30 @@ func (c *Config) CAClientCertPem(org string) (string, error) {
return ca.TLSCACerts.Client.Cert.Pem, nil
}

// TimeoutOrDefault reads connection timeouts for the given timeout type, if not found, defaultTimeout is returned
func (c *Config) TimeoutOrDefault(conn core.TimeoutType) time.Duration {
timeout := c.getTimeout(conn)
// TimeoutOrDefault reads timeouts for the given timeout type, if not found, defaultTimeout is returned
func (c *Config) TimeoutOrDefault(tType core.TimeoutType) time.Duration {
timeout := c.getTimeout(tType)
if timeout == 0 {
timeout = defaultTimeout
}

return timeout
}

// Timeout reads connection timeouts for the given timeout type, the default is 0 if type is not found in config
func (c *Config) Timeout(conn core.TimeoutType) time.Duration {
return c.getTimeout(conn)
// Timeout reads timeouts for the given timeout type, the default is 0 if type is not found in config
func (c *Config) Timeout(tType core.TimeoutType) time.Duration {
return c.getTimeout(tType)
}

func (c *Config) getTimeout(conn core.TimeoutType) time.Duration {
func (c *Config) getTimeout(tType core.TimeoutType) time.Duration {
var timeout time.Duration
switch conn {
switch tType {
case core.EndorserConnection:
timeout = c.configViper.GetDuration("client.peer.timeout.connection")
case core.Query:
timeout = c.configViper.GetDuration("client.peer.timeout.queryResponse")
timeout = c.configViper.GetDuration("client.global.timeout.query")
case core.Execute:
timeout = c.configViper.GetDuration("client.peer.timeout.executeTxResponse")
timeout = c.configViper.GetDuration("client.global.timeout.execute")
case core.DiscoveryGreylistExpiry:
timeout = c.configViper.GetDuration("client.peer.timeout.discovery.greylistExpiry")
case core.EventHubConnection:
Expand All @@ -487,7 +487,7 @@ func (c *Config) getTimeout(conn core.TimeoutType) time.Duration {
timeout = defaultCacheSweepInterval
}
case core.ConnectionIdle:
timeout = c.configViper.GetDuration("client.cache.timeout.connectionIdle")
timeout = c.configViper.GetDuration("client.global.timeout.cache.connectionIdle")
if timeout == 0 {
timeout = defaultConnIdleTimeout
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/core/config/config_test.go
Expand Up @@ -376,8 +376,9 @@ func TestTimeouts(t *testing.T) {
configImpl.configViper.Set("client.eventService.timeout.connection", "2m")
configImpl.configViper.Set("client.eventService.timeout.registrationResponse", "2h")
configImpl.configViper.Set("client.orderer.timeout.connection", "2ms")
configImpl.configViper.Set("client.peer.timeout.queryResponse", "7h")
configImpl.configViper.Set("client.peer.timeout.executeTxResponse", "8h")
configImpl.configViper.Set("client.global.timeout.query", "7h")
configImpl.configViper.Set("client.global.timeout.execute", "8h")
configImpl.configViper.Set("client.global.timeout.cache.connectionIdle", "1m")
configImpl.configViper.Set("client.orderer.timeout.response", "6s")

t1 := configImpl.TimeoutOrDefault(api.EndorserConnection)
Expand Down Expand Up @@ -408,6 +409,10 @@ func TestTimeouts(t *testing.T) {
if t1 != time.Second*6 {
t.Fatalf("Timeout not read correctly. Got: %s", t1)
}
t1 = configImpl.TimeoutOrDefault(api.ConnectionIdle)
if t1 != time.Minute*1 {
t.Fatalf("Timeout not read correctly. Got: %s", t1)
}

// Test default
configImpl.configViper.Set("client.orderer.timeout.connection", "")
Expand Down
8 changes: 6 additions & 2 deletions pkg/core/config/testdata/config_test_pem.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
greylistExpiry: 5s
eventService:
Expand All @@ -59,6 +57,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s


# Needed to load users crypto keys and certs.
Expand Down
8 changes: 6 additions & 2 deletions pkg/core/config/testdata/template/config.yaml
Expand Up @@ -48,8 +48,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 20s
executeTxResponse: 60s
discovery:
greylistExpiry: 5s
eventService:
Expand All @@ -60,6 +58,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s

# Needed to load users crypto keys and certs.
cryptoconfig:
Expand Down
10 changes: 7 additions & 3 deletions pkg/core/identitymgr/testdata/config_embedded_registrar.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s

# Root of the MSP directories with keys and certs.
cryptoconfig:
Expand Down Expand Up @@ -306,7 +310,7 @@ certificateAuthorities:
# needed to enroll and invoke new users.
registrar:
enrollId: EmbeddedRegistrar
# Absense of the enrollSecret requires that the registrar is embedded or already enrolled
# Absence of the enrollSecret requires that the registrar is embedded or already enrolled
#enrollSecret: EmbeddedRegistrarPw
# [Optional] The optional name of the CA.
caName: ca.org1.example.com
8 changes: 6 additions & 2 deletions pkg/core/identitymgr/testdata/config_no_registrar.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s

# Root of the MSP directories with keys and certs.
cryptoconfig:
Expand Down
8 changes: 6 additions & 2 deletions pkg/core/identitymgr/testdata/config_test.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s

# Root of the MSP directories with keys and certs.
cryptoconfig:
Expand Down
8 changes: 6 additions & 2 deletions pkg/core/identitymgr/testdata/config_test_wrong_url.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s

# Root of the MSP directories with keys and certs.
cryptoconfig:
Expand Down
8 changes: 6 additions & 2 deletions pkg/fabsdk/testdata/test.yaml
Expand Up @@ -22,8 +22,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 20s
executeTxResponse: 30s
discovery:
greylistExpiry: 5s
eventService:
Expand All @@ -34,6 +32,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 20s
execute: 30s
cache:
connectionIdle: 30s

cryptoconfig:
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/config/config_pkcs11_test.yaml
Expand Up @@ -46,8 +46,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -62,8 +60,11 @@ client:
timeout:
connection: 3s
response: 5s
cache:
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s


Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/config/config_test.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,8 +61,11 @@ client:
timeout:
connection: 3s
response: 5s
cache:
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s


Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/config/config_test_embedded_pems.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will lock peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s


# Needed to load users crypto keys and certs.
Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/config/config_test_no_orderer.yaml
Expand Up @@ -47,8 +47,6 @@ client:
peer:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 60s
discovery:
# Expiry period for discovery service greylist filter
# The channel client will greylist peers that are found to be offline
Expand All @@ -63,6 +61,12 @@ client:
timeout:
connection: 3s
response: 5s
global:
timeout:
query: 45s
execute: 60s
cache:
connectionIdle: 30s


# Needed to load users crypto keys and certs.
Expand Down

0 comments on commit 9394d3c

Please sign in to comment.