diff options
-rw-r--r-- | server_config.go | 4 | ||||
-rw-r--r-- | server_config_test.go | 44 | ||||
-rw-r--r-- | service/env/service.go | 6 | ||||
-rw-r--r-- | service/env/service_test.go | 10 | ||||
-rw-r--r-- | service/rpc/service.go | 6 |
5 files changed, 64 insertions, 6 deletions
diff --git a/server_config.go b/server_config.go index 1d8c281c..e2f9266b 100644 --- a/server_config.go +++ b/server_config.go @@ -43,6 +43,10 @@ func (cfg *ServerConfig) SetDefaults() { cfg.RelayTimeout = time.Minute } + if cfg.Pool == nil { + cfg.Pool = &Config{} + } + if cfg.Pool.AllocateTimeout == 0 { cfg.Pool.AllocateTimeout = time.Minute } diff --git a/server_config_test.go b/server_config_test.go index 1831ae95..e116323d 100644 --- a/server_config_test.go +++ b/server_config_test.go @@ -4,6 +4,7 @@ import ( "github.com/stretchr/testify/assert" "runtime" "testing" + "time" ) func Test_ServerConfig_PipeFactory(t *testing.T) { @@ -90,3 +91,46 @@ func Test_ServerConfig_Cmd(t *testing.T) { cmd := cfg.makeCommand() assert.NotNil(t, cmd) } + +func Test_ServerConfig_SetEnv(t *testing.T) { + cfg := &ServerConfig{ + Command: "php php-src/tests/client.php pipes", + } + + cfg.SetEnv("key", "value") + + cmd := cfg.makeCommand() + assert.NotNil(t, cmd) + + c := cmd() + + assert.Contains(t, c.Env, "KEY=value") +} + +func Test_ServerConfigDefaults(t *testing.T) { + cfg := &ServerConfig{ + Command: "php php-src/tests/client.php pipes", + } + + cfg.SetDefaults() + + assert.Equal(t, "pipes", cfg.Relay) + assert.Equal(t, time.Minute, cfg.Pool.AllocateTimeout) + assert.Equal(t, time.Minute, cfg.Pool.DestroyTimeout) +} + +func Test_Config_Upscale(t *testing.T) { + cfg := &ServerConfig{ + Command: "php php-src/tests/client.php pipes", + RelayTimeout: 1, + Pool: &Config{ + AllocateTimeout: 1, + DestroyTimeout: 1, + }, + } + + cfg.UpscaleDurations() + assert.Equal(t, time.Second, cfg.RelayTimeout) + assert.Equal(t, time.Second, cfg.Pool.AllocateTimeout) + assert.Equal(t, time.Second, cfg.Pool.DestroyTimeout) +} diff --git a/service/env/service.go b/service/env/service.go index a4d3959c..41e70bee 100644 --- a/service/env/service.go +++ b/service/env/service.go @@ -4,8 +4,8 @@ const ( // ID contains default service name. ID = "env" - // RRKey contains default env key to indicate than php running in RR mode. - RRKey = "RR" + // rrKey contains default env key to indicate than php running in RR mode. + rrKey = "rr" ) // Service provides ability to map _ENV values from config file. @@ -25,7 +25,7 @@ func NewService(defaults map[string]string) *Service { func (s *Service) Init(cfg *Config) (bool, error) { if s.values == nil { s.values = make(map[string]string) - s.values[RRKey] = "yes" + s.values[rrKey] = "yes" } for k, v := range cfg.Values { diff --git a/service/env/service_test.go b/service/env/service_test.go index 5b148207..28e0d15b 100644 --- a/service/env/service_test.go +++ b/service/env/service_test.go @@ -10,6 +10,16 @@ func Test_NewService(t *testing.T) { assert.Len(t, s.values, 1) } +func Test_Init(t *testing.T) { + s := &Service{} + s.Init(&Config{}) + assert.Len(t, s.values, 1) + + values, err := s.GetEnv() + assert.NoError(t, err) + assert.Equal(t, "yes", values["rr"]) +} + func Test_Extend(t *testing.T) { s := NewService(map[string]string{"rr": "version"}) diff --git a/service/rpc/service.go b/service/rpc/service.go index 14e34319..d8c2b9d5 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -12,9 +12,9 @@ const ( // ID contains default service name. ID = "rpc" - // RRKey defines environment key to be used to store information about + // rrKey defines environment key to be used to store information about // rpc server connection. - EnvKey = "RR_RPC" + envKey = "rr-rpc" ) // Service is RPC service. @@ -36,7 +36,7 @@ func (s *Service) Init(cfg *Config, env env.Environment) (bool, error) { s.rpc = rpc.NewServer() if env != nil { - env.SetEnv(EnvKey, cfg.Listen) + env.SetEnv(envKey, cfg.Listen) } return true, nil |