mirror of
https://github.com/openfaas/faas.git
synced 2025-06-10 01:06:47 +00:00
Use time / duration for config
This commit is contained in:
parent
ed47c36d59
commit
5db6013861
@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type EnvBucket struct {
|
type EnvBucket struct {
|
||||||
Items map[string]string
|
Items map[string]string
|
||||||
@ -62,11 +65,11 @@ func TestRead_EmptyTimeoutConfig(t *testing.T) {
|
|||||||
|
|
||||||
config := readConfig.Read(defaults)
|
config := readConfig.Read(defaults)
|
||||||
|
|
||||||
if (config.readTimeout) != 5 {
|
if (config.readTimeout) != time.Duration(5)*time.Second {
|
||||||
t.Log("readTimeout incorrect")
|
t.Log("readTimeout incorrect")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
if (config.writeTimeout) != 5 {
|
if (config.writeTimeout) != time.Duration(5)*time.Second {
|
||||||
t.Log("writeTimeout incorrect")
|
t.Log("writeTimeout incorrect")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
@ -80,11 +83,11 @@ func TestRead_ReadAndWriteTimeoutConfig(t *testing.T) {
|
|||||||
readConfig := ReadConfig{}
|
readConfig := ReadConfig{}
|
||||||
config := readConfig.Read(defaults)
|
config := readConfig.Read(defaults)
|
||||||
|
|
||||||
if (config.readTimeout) != 10 {
|
if (config.readTimeout) != time.Duration(10)*time.Second {
|
||||||
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
|
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
if (config.writeTimeout) != 60 {
|
if (config.writeTimeout) != time.Duration(60)*time.Second {
|
||||||
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
|
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "strconv"
|
import (
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// HasEnv provides interface for os.Getenv
|
// HasEnv provides interface for os.Getenv
|
||||||
type HasEnv interface {
|
type HasEnv interface {
|
||||||
@ -42,16 +45,16 @@ func (ReadConfig) Read(hasEnv HasEnv) WatchdogConfig {
|
|||||||
writeTimeout := parseIntValue(hasEnv.Getenv("write_timeout"))
|
writeTimeout := parseIntValue(hasEnv.Getenv("write_timeout"))
|
||||||
|
|
||||||
if readTimeout == 0 {
|
if readTimeout == 0 {
|
||||||
cfg.readTimeout = 5
|
readTimeout = 5
|
||||||
} else {
|
|
||||||
cfg.readTimeout = readTimeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if writeTimeout == 0 {
|
if writeTimeout == 0 {
|
||||||
cfg.writeTimeout = 5
|
writeTimeout = 5
|
||||||
} else {
|
|
||||||
cfg.writeTimeout = writeTimeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.readTimeout = time.Duration(readTimeout) * time.Second
|
||||||
|
cfg.writeTimeout = time.Duration(writeTimeout) * time.Second
|
||||||
|
|
||||||
cfg.writeDebug = parseBoolValue(hasEnv.Getenv("write_debug"))
|
cfg.writeDebug = parseBoolValue(hasEnv.Getenv("write_debug"))
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
@ -59,8 +62,8 @@ func (ReadConfig) Read(hasEnv HasEnv) WatchdogConfig {
|
|||||||
|
|
||||||
// WatchdogConfig for the process.
|
// WatchdogConfig for the process.
|
||||||
type WatchdogConfig struct {
|
type WatchdogConfig struct {
|
||||||
readTimeout int
|
readTimeout time.Duration
|
||||||
writeTimeout int
|
writeTimeout time.Duration
|
||||||
// faasProcess is the process to exec
|
// faasProcess is the process to exec
|
||||||
faasProcess string
|
faasProcess string
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user