From cac8bf48bab69ff3468cf7d30ac1c18904885a47 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:26:26 +0300 Subject: added ability to alter env values --- service/env/provider.go | 7 +++++-- service/env/service.go | 7 ++++++- service/env/service_test.go | 18 ++++++++++++++++++ service/http/config.go | 6 +++++- service/http/service.go | 4 ++-- service/rpc/service.go | 16 +++++++++++++--- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/service/env/provider.go b/service/env/provider.go index 2918f18c..d095009c 100644 --- a/service/env/provider.go +++ b/service/env/provider.go @@ -2,7 +2,10 @@ package env // Provider aggregates list of environment variables. This interface can be used in custom implementation to drive // values from external sources. -type Provider interface { +type Environment interface { // GetEnv must return list of env variables. GetEnv() (map[string]string, error) -} + + // SetEnv sets or creates environment value. + SetEnv(key, value string) +} \ No newline at end of file diff --git a/service/env/service.go b/service/env/service.go index 0822d55a..b32a2f2b 100644 --- a/service/env/service.go +++ b/service/env/service.go @@ -15,7 +15,7 @@ func NewService(defaults map[string]string) *Service { if s.values == nil { s.values = make(map[string]string) } - + return s } @@ -33,3 +33,8 @@ func (s *Service) Init(cfg *Config) (bool, error) { func (s *Service) GetEnv() (map[string]string, error) { return s.values, nil } + +// SetEnv sets or creates environment value. +func (s *Service) SetEnv(key, value string) { + s.values[key] = value +} diff --git a/service/env/service_test.go b/service/env/service_test.go index 69a2a375..10159857 100644 --- a/service/env/service_test.go +++ b/service/env/service_test.go @@ -22,3 +22,21 @@ func Test_Extend(t *testing.T) { assert.Equal(t, "version", values["rr"]) assert.Equal(t, "value", values["key"]) } + + +func Test_Set(t *testing.T) { + s := NewService(map[string]string{"rr": "version"}) + + s.Init(&Config{Values: map[string]string{"key": "value"}}) + assert.Len(t, s.values, 2) + + s.SetEnv("key","value-new") + s.SetEnv("other","new") + + values, err := s.GetEnv() + assert.NoError(t, err) + assert.Len(t, values, 3) + assert.Equal(t, "version", values["rr"]) + assert.Equal(t, "value-new", values["key"]) + assert.Equal(t, "new", values["other"]) +} \ No newline at end of file diff --git a/service/http/config.go b/service/http/config.go index 20a247fb..3e08c72d 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -10,7 +10,7 @@ import ( // Config configures RoadRunner HTTP server. type Config struct { - // Enable enables http svc. + // Enable enables http service. Enable bool // Address and port to handle as http server. @@ -32,6 +32,10 @@ func (c *Config) Hydrate(cfg service.Config) error { return err } + if !c.Enable { + return nil + } + if err := c.Valid(); err != nil { return err } diff --git a/service/http/service.go b/service/http/service.go index 9f62f5af..f988a843 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -20,7 +20,7 @@ type middleware func(f http.HandlerFunc) http.HandlerFunc // Service manages rr, http servers. type Service struct { cfg *Config - env env.Provider + env env.Environment lsns []func(event int, ctx interface{}) mdws []middleware mu sync.Mutex @@ -42,7 +42,7 @@ func (s *Service) AddListener(l func(event int, ctx interface{})) { // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. -func (s *Service) Init(cfg *Config, r *rpc.Service, e env.Provider) (bool, error) { +func (s *Service) Init(cfg *Config, r *rpc.Service, e env.Environment) (bool, error) { if !cfg.Enable { return false, nil } diff --git a/service/rpc/service.go b/service/rpc/service.go index 6e231048..abeae240 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -5,11 +5,17 @@ import ( "github.com/spiral/goridge" "net/rpc" "sync" + "github.com/spiral/roadrunner/service/env" ) -// ID contains default service name. -const ID = "rpc" +const ( + // ID contains default service name. + ID = "rpc" + // ENV_KEY defines environment key to be used to store information about + // rpc server connection. + ENV_KEY = "RR_RPC" +) // Service is RPC service. type Service struct { cfg *Config @@ -20,7 +26,7 @@ type Service struct { } // Init rpc service. Must return true if service is enabled. -func (s *Service) Init(cfg *Config) (bool, error) { +func (s *Service) Init(cfg *Config, env env.Environment) (bool, error) { if !cfg.Enable { return false, nil } @@ -28,6 +34,10 @@ func (s *Service) Init(cfg *Config) (bool, error) { s.cfg = cfg s.rpc = rpc.NewServer() + if env != nil { + env.SetEnv(ENV_KEY, cfg.Listen) + } + return true, nil } -- cgit v1.2.3 From f0bc4fc0da3a00cee746535bd9817f31e97bcb0d Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:37:09 +0300 Subject: added ability to alter env values --- cmd/rr/http/debug.go | 1 + 1 file changed, 1 insertion(+) create mode 100644 cmd/rr/http/debug.go diff --git a/cmd/rr/http/debug.go b/cmd/rr/http/debug.go new file mode 100644 index 00000000..d02cfda6 --- /dev/null +++ b/cmd/rr/http/debug.go @@ -0,0 +1 @@ +package http -- cgit v1.2.3 From 4dea95a525707af1a726e9af024e4abdbde28820 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:37:28 +0300 Subject: improved debug handlers (moved from common package) --- cmd/rr/cmd/root.go | 36 +++++++++++++++++------------------- cmd/rr/http/debug.go | 19 +++++++++++++++++++ cmd/rr/main.go | 11 ++++------- service/env/service.go | 18 ++++++++++++------ 4 files changed, 52 insertions(+), 32 deletions(-) diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index 595395c0..5e936580 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -24,17 +24,20 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/spiral/roadrunner/cmd/rr/debug" "github.com/spiral/roadrunner/cmd/rr/utils" "github.com/spiral/roadrunner/service" - "github.com/spiral/roadrunner/service/http" "os" ) // Service bus for all the commands. var ( - cfgFile string - verbose, debugMode bool + cfgFile string + + // Verbose enables verbosity mode (container specific). + Verbose bool + + // Debug enables debug mode (service specific). + Debug bool // Logger - shared logger. Logger = logrus.New() @@ -78,6 +81,13 @@ func (w *ViperWrapper) Unmarshal(out interface{}) error { // Execute adds all child commands to the CLI command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the CLI. func Execute() { + if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil { + if err := Container.Init(cfg); err != nil { + utils.Printf("Error: %s\n", err) + os.Exit(1) + } + } + if err := CLI.Execute(); err != nil { utils.Printf("Error: %s\n", err) os.Exit(1) @@ -85,26 +95,14 @@ func Execute() { } func init() { - CLI.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") - CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode") + CLI.PersistentFlags().BoolVarP(&Verbose, "Verbose", "v", false, "Verbose output") + CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode") CLI.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is .rr.yaml)") cobra.OnInitialize(func() { - if verbose { + if Verbose { Logger.SetLevel(logrus.DebugLevel) } - - if debugMode { - svc, _ := Container.Get(http.ID) - svc.(*http.Service).AddListener(debug.Listener(Logger)) - } - - if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil { - if err := Container.Init(cfg); err != nil { - utils.Printf("Error: %s\n", err) - os.Exit(1) - } - } }) } diff --git a/cmd/rr/http/debug.go b/cmd/rr/http/debug.go index d02cfda6..cae10452 100644 --- a/cmd/rr/http/debug.go +++ b/cmd/rr/http/debug.go @@ -1 +1,20 @@ package http + +import ( + rr "github.com/spiral/roadrunner/cmd/rr/cmd" + + "github.com/spf13/cobra" + "github.com/spiral/roadrunner/service/http" + "github.com/spiral/roadrunner/cmd/rr/debug" +) + +func init(){ + cobra.OnInitialize(func() { + if rr.Debug { + svc, _ := rr.Container.Get(http.ID) + if svc, ok := svc.(*http.Service); ok { + svc.AddListener(debug.Listener(rr.Logger)) + } + } + }) +} \ No newline at end of file diff --git a/cmd/rr/main.go b/cmd/rr/main.go index 01a5aaf3..c4eac19b 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -23,9 +23,6 @@ package main import ( - // colorful logging - "github.com/sirupsen/logrus" - rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) @@ -36,17 +33,17 @@ import ( // additional command handlers _ "github.com/spiral/roadrunner/cmd/rr/http" + "github.com/sirupsen/logrus" ) func main() { - rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true} - - rr.Container.Register(env.ID, env.NewService(map[string]string{"rr": rr.Version})) - + rr.Container.Register(env.ID, &env.Service{}) rr.Container.Register(rpc.ID, &rpc.Service{}) rr.Container.Register(http.ID, &http.Service{}) rr.Container.Register(static.ID, &static.Service{}) + rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true} + // you can register additional commands using cmd.CLI rr.Execute() } diff --git a/service/env/service.go b/service/env/service.go index b32a2f2b..561907a0 100644 --- a/service/env/service.go +++ b/service/env/service.go @@ -1,7 +1,12 @@ package env -// ID contains default svc name. -const ID = "env" +const ( + // ID contains default service name. + ID = "env" + + // RR_ENV contains default env key to indicate than php running in RR mode. + RR_ENV = "RR" +) // Service provides ability to map _ENV values from config file. type Service struct { @@ -12,16 +17,17 @@ type Service struct { // NewService creates new env service instance for given rr version. func NewService(defaults map[string]string) *Service { s := &Service{values: defaults} - if s.values == nil { - s.values = make(map[string]string) - } - return s } // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. func (s *Service) Init(cfg *Config) (bool, error) { + if s.values == nil { + s.values = make(map[string]string) + s.values[RR_ENV] = "yes" + } + for k, v := range cfg.Values { s.values[k] = v } -- cgit v1.2.3 From de629f78c9dddf23d5d79ae49dc5ab8545d0829e Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:38:46 +0300 Subject: improved debug configuration, added env setters --- cmd/rr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/rr/main.go b/cmd/rr/main.go index c4eac19b..ca3ca9ac 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -24,6 +24,7 @@ package main import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" + "github.com/sirupsen/logrus" // services (plugins) "github.com/spiral/roadrunner/service/env" @@ -33,7 +34,6 @@ import ( // additional command handlers _ "github.com/spiral/roadrunner/cmd/rr/http" - "github.com/sirupsen/logrus" ) func main() { -- cgit v1.2.3 From 03cf0bac705b83828b6b465363ec68b9f733b7ae Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:39:23 +0300 Subject: improved debug configuration, added env setters --- service/env/environment.go | 11 +++++++++++ service/env/provider.go | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 service/env/environment.go delete mode 100644 service/env/provider.go diff --git a/service/env/environment.go b/service/env/environment.go new file mode 100644 index 00000000..d095009c --- /dev/null +++ b/service/env/environment.go @@ -0,0 +1,11 @@ +package env + +// Provider aggregates list of environment variables. This interface can be used in custom implementation to drive +// values from external sources. +type Environment interface { + // GetEnv must return list of env variables. + GetEnv() (map[string]string, error) + + // SetEnv sets or creates environment value. + SetEnv(key, value string) +} \ No newline at end of file diff --git a/service/env/provider.go b/service/env/provider.go deleted file mode 100644 index d095009c..00000000 --- a/service/env/provider.go +++ /dev/null @@ -1,11 +0,0 @@ -package env - -// Provider aggregates list of environment variables. This interface can be used in custom implementation to drive -// values from external sources. -type Environment interface { - // GetEnv must return list of env variables. - GetEnv() (map[string]string, error) - - // SetEnv sets or creates environment value. - SetEnv(key, value string) -} \ No newline at end of file -- cgit v1.2.3 From aec7ab39e0221da8df7f2e00113eefcea27692cd Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:42:08 +0300 Subject: missing config warning has been converted into debug message (-v flag is required) --- service/container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/container.go b/service/container.go index 3450a18c..c1d21c69 100644 --- a/service/container.go +++ b/service/container.go @@ -133,7 +133,7 @@ func (c *container) Init(cfg Config) error { if ok, err := c.initService(e.svc, cfg.Get(e.name)); err != nil { // soft error (skipping) if err == errNoConfig { - c.log.Warningf("[%s]: no config has been provided", e.name) + c.log.Debugf("[%s]: no config has been provided", e.name) continue } -- cgit v1.2.3 From 2e7cb626f0c7391002d562a3e9598105c189ea71 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:46:14 +0300 Subject: better default values for worker config --- service/http/config.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/http/config.go b/service/http/config.go index 3e08c72d..a15edb35 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -44,6 +44,10 @@ func (c *Config) Hydrate(cfg service.Config) error { c.Workers.Relay = "pipes" } + c.Workers.MountDefaults() + + // nanosecond to second conversion + if c.Workers.RelayTimeout < time.Microsecond { c.Workers.RelayTimeout = time.Second * time.Duration(c.Workers.RelayTimeout.Nanoseconds()) } -- cgit v1.2.3 From 64fc57065b59c36a280fd0aac8a4e98c20d0824d Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:48:09 +0300 Subject: better static service root directory error --- service/static/config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service/static/config.go b/service/static/config.go index a6931907..0ec1c8d8 100644 --- a/service/static/config.go +++ b/service/static/config.go @@ -1,11 +1,11 @@ package static import ( - "github.com/pkg/errors" "github.com/spiral/roadrunner/service" "os" "path" "strings" + "fmt" ) // Config describes file location and controls access to them. @@ -35,18 +35,18 @@ func (c *Config) Valid() error { if !c.Enable { return nil } - + st, err := os.Stat(c.Dir) if err != nil { if os.IsNotExist(err) { - return errors.New("root directory does not exists") + return fmt.Errorf("root directory '%s' does not exists", c.Dir) } return err } if !st.IsDir() { - return errors.New("invalid root directory") + return fmt.Errorf("invalid root directory '%s'", c.Dir) } return nil -- cgit v1.2.3 From 487d7c52ef2fc911606e756035a08292b3bd0128 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:49:19 +0300 Subject: better static service root directory error --- error_buffer.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/error_buffer.go b/error_buffer.go index 211fe25f..fec789a9 100644 --- a/error_buffer.go +++ b/error_buffer.go @@ -6,11 +6,12 @@ import ( ) const ( - // EventStderrOutput - is triggered when worker sends data into stderr. The context is error message ([]byte). + // EventStderrOutput - is triggered when worker sends data into stderr. The context + // is error message ([]byte). EventStderrOutput = 1900 - // WaitDuration - for how long error buffer should attempt to aggregate error messages before merging output - // together since lastError update (required to keep error update together). + // WaitDuration - for how long error buffer should attempt to aggregate error messages + // before merging output together since lastError update (required to keep error update together). WaitDuration = 100 * time.Millisecond ) -- cgit v1.2.3 From bf086da11191848ef3a74602d4c652034357e972 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Fri, 7 Sep 2018 23:58:01 +0300 Subject: added support for logger in DI --- service/container.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/container.go b/service/container.go index c1d21c69..b6840375 100644 --- a/service/container.go +++ b/service/container.go @@ -251,6 +251,11 @@ func (c *container) resolveValues(s interface{}, m reflect.Method, cfg Config) ( case v.Implements(reflect.TypeOf((*Container)(nil)).Elem()): // container values = append(values, reflect.ValueOf(c)) + case v.Implements(reflect.TypeOf((*logrus.StdLogger)(nil)).Elem()), + v.Implements(reflect.TypeOf((*logrus.FieldLogger)(nil)).Elem()), + v.ConvertibleTo(reflect.ValueOf(c.log).Type()): // logger + values = append(values, reflect.ValueOf(c.log)) + case v.Implements(reflect.TypeOf((*HydrateConfig)(nil)).Elem()): // injectable config if cfg == nil { return nil, errNoConfig -- cgit v1.2.3 From fc7f7f7ac17ef0838bbdfd578b4e17821b287aee Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:01:03 +0300 Subject: added support for logger in DI --- service/container.go | 2 +- service/env/service.go | 6 +++--- service/rpc/service.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/service/container.go b/service/container.go index b6840375..1716b965 100644 --- a/service/container.go +++ b/service/container.go @@ -213,7 +213,7 @@ func (c *container) Stop() { func (c *container) initService(s interface{}, segment Config) (bool, error) { r := reflect.TypeOf(s) - m, ok := r.MethodByName("Init") + m, ok := r.MethodByName(InitMethod) if !ok { // no Init method is presented, assuming service does not need initialization. return true, nil diff --git a/service/env/service.go b/service/env/service.go index 561907a0..a4d3959c 100644 --- a/service/env/service.go +++ b/service/env/service.go @@ -4,8 +4,8 @@ const ( // ID contains default service name. ID = "env" - // RR_ENV contains default env key to indicate than php running in RR mode. - RR_ENV = "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[RR_ENV] = "yes" + s.values[RRKey] = "yes" } for k, v := range cfg.Values { diff --git a/service/rpc/service.go b/service/rpc/service.go index abeae240..9cd32755 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -12,9 +12,9 @@ const ( // ID contains default service name. ID = "rpc" - // ENV_KEY defines environment key to be used to store information about + // RRKey defines environment key to be used to store information about // rpc server connection. - ENV_KEY = "RR_RPC" + EnvKey = "RR_RPC" ) // Service is RPC service. type Service struct { @@ -35,7 +35,7 @@ func (s *Service) Init(cfg *Config, env env.Environment) (bool, error) { s.rpc = rpc.NewServer() if env != nil { - env.SetEnv(ENV_KEY, cfg.Listen) + env.SetEnv(EnvKey, cfg.Listen) } return true, nil -- cgit v1.2.3 From 80ef824cabc1ab17c7c6584be85cb825be7a70af Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:02:20 +0300 Subject: added support for logger in DI --- service/container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/container.go b/service/container.go index 1716b965..861e1aac 100644 --- a/service/container.go +++ b/service/container.go @@ -152,7 +152,7 @@ func (c *container) Init(cfg Config) error { // Serve all configured services. Non blocking. func (c *container) Serve() error { var ( - numServing int + numServing = 0 done = make(chan interface{}, len(c.services)) ) -- cgit v1.2.3 From db2a073d99d00c09ebdc5624876123cbcb97ea6b Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:04:56 +0300 Subject: changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d201b38f..b5403919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ CHANGELOG ========= +v1.2.0 +------- +- added ability to request `*logrus.Logger`, `logrus.StdLogger`, `logrus.FieldLogger` dependency +in container +- added ability to set env values using `env.Enviroment` +- `env.Provider` renamed to `env.Enviroment` +- rr does not throw warning when service config is missing, instead debug level is used +- + v1.1.1 (26.07.2018) ------- - added support for custom env variables -- cgit v1.2.3 From 9d8ac450cb837d0528bf5721b9901134ae623518 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:08:19 +0300 Subject: changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5403919..8094cae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ in container - added ability to set env values using `env.Enviroment` - `env.Provider` renamed to `env.Enviroment` - rr does not throw warning when service config is missing, instead debug level is used -- +- rr server config now support default value set (shorter configs) +- debug handlers has been moved from root command and now can be defined by each service +- bugfix: panic when using debug mode without http service registered +- `rr.Verbose` and `rr.Debug` are not public v1.1.1 (26.07.2018) ------- -- cgit v1.2.3 From 24b50941c91dbd1067fc4b143085fda504321a8b Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:09:33 +0300 Subject: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8094cae1..a980efab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ in container - debug handlers has been moved from root command and now can be defined by each service - bugfix: panic when using debug mode without http service registered - `rr.Verbose` and `rr.Debug` are not public +- rpc service now exposes it's address to underlying workers to simplify the connection +- env service construction has been simplified in order to unify it with other services v1.1.1 (26.07.2018) ------- -- cgit v1.2.3 From d8032d0512f59b34ec334cdac7b7ce2d8fe7f6c1 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sat, 8 Sep 2018 00:10:15 +0300 Subject: changelog --- cmd/rr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/rr/main.go b/cmd/rr/main.go index ca3ca9ac..da34a62b 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -32,7 +32,7 @@ import ( "github.com/spiral/roadrunner/service/rpc" "github.com/spiral/roadrunner/service/static" - // additional command handlers + // additional command and debug handlers _ "github.com/spiral/roadrunner/cmd/rr/http" ) -- cgit v1.2.3 From 569a0dec066ea53fd6d0a2080362db67fd794557 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 14:19:52 +0300 Subject: changelog --- server_config.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server_config.go b/server_config.go index 88d15e1f..1a24e335 100644 --- a/server_config.go +++ b/server_config.go @@ -33,6 +33,21 @@ type ServerConfig struct { env []string } +// SetDefaults sets missing values to their default values. +func (cfg *ServerConfig) SetDefaults() { + if cfg.RelayTimeout == 0 { + cfg.RelayTimeout = time.Minute + } + + if cfg.Pool.AllocateTimeout == 0 { + cfg.Pool.AllocateTimeout = time.Minute + } + + if cfg.Pool.DestroyTimeout == 0 { + cfg.Pool.DestroyTimeout = time.Minute + } +} + // Differs returns true if configuration has changed but ignores pool or cmd changes. func (cfg *ServerConfig) Differs(new *ServerConfig) bool { return cfg.Relay != new.Relay || cfg.RelayTimeout != new.RelayTimeout -- cgit v1.2.3 From ceb5033d5bb2fb641c886d4010f05498552152c2 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 14:28:15 +0300 Subject: minor config improvements --- service/http/config.go | 24 +++--------------------- service/rpc/service_test.go | 10 +++++----- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/service/http/config.go b/service/http/config.go index a15edb35..2cfe1ba2 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -5,7 +5,6 @@ import ( "github.com/spiral/roadrunner" "github.com/spiral/roadrunner/service" "strings" - "time" ) // Config configures RoadRunner HTTP server. @@ -36,30 +35,13 @@ func (c *Config) Hydrate(cfg service.Config) error { return nil } + c.Workers.SetDefaults() + c.Workers.UpscaleDurations() + if err := c.Valid(); err != nil { return err } - if c.Workers.Relay == "" { - c.Workers.Relay = "pipes" - } - - c.Workers.MountDefaults() - - // nanosecond to second conversion - - if c.Workers.RelayTimeout < time.Microsecond { - c.Workers.RelayTimeout = time.Second * time.Duration(c.Workers.RelayTimeout.Nanoseconds()) - } - - if c.Workers.Pool.AllocateTimeout < time.Microsecond { - c.Workers.Pool.AllocateTimeout = time.Second * time.Duration(c.Workers.Pool.AllocateTimeout.Nanoseconds()) - } - - if c.Workers.Pool.DestroyTimeout < time.Microsecond { - c.Workers.Pool.DestroyTimeout = time.Second * time.Duration(c.Workers.Pool.DestroyTimeout.Nanoseconds()) - } - return nil } diff --git a/service/rpc/service_test.go b/service/rpc/service_test.go index fc88d38d..e47e9cdd 100644 --- a/service/rpc/service_test.go +++ b/service/rpc/service_test.go @@ -12,7 +12,7 @@ func (ts *testService) Echo(msg string, r *string) error { *r = msg; return nil func Test_Disabled(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: false}) + ok, err := s.Init(&Config{Enable: false}, nil) assert.NoError(t, err) assert.False(t, ok) @@ -30,7 +30,7 @@ func Test_RegisterNotConfigured(t *testing.T) { func Test_Enabled(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"},nil) assert.NoError(t, err) assert.True(t, ok) @@ -38,7 +38,7 @@ func Test_Enabled(t *testing.T) { func Test_StopNonServing(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"},nil) assert.NoError(t, err) assert.True(t, ok) @@ -47,7 +47,7 @@ func Test_StopNonServing(t *testing.T) { func Test_Serve_Errors(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"}) + ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"},nil) assert.NoError(t, err) assert.True(t, ok) @@ -60,7 +60,7 @@ func Test_Serve_Errors(t *testing.T) { func Test_Serve_Client(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"},nil) assert.NoError(t, err) assert.True(t, ok) -- cgit v1.2.3 From 7ab1e77f2db902cf8a485e3a28bfdbd58a613dc9 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 14:29:10 +0300 Subject: go fmt --- cmd/rr/http/debug.go | 6 +++--- cmd/rr/main.go | 2 +- git | 0 server_config.go | 19 +++++++++++++++++++ service/env/environment.go | 2 +- service/env/service_test.go | 7 +++---- service/http/service_test.go | 2 +- service/rpc/service.go | 3 ++- service/rpc/service_test.go | 8 ++++---- service/static/config.go | 2 +- 10 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 git diff --git a/cmd/rr/http/debug.go b/cmd/rr/http/debug.go index cae10452..f69e10a8 100644 --- a/cmd/rr/http/debug.go +++ b/cmd/rr/http/debug.go @@ -4,11 +4,11 @@ import ( rr "github.com/spiral/roadrunner/cmd/rr/cmd" "github.com/spf13/cobra" - "github.com/spiral/roadrunner/service/http" "github.com/spiral/roadrunner/cmd/rr/debug" + "github.com/spiral/roadrunner/service/http" ) -func init(){ +func init() { cobra.OnInitialize(func() { if rr.Debug { svc, _ := rr.Container.Get(http.ID) @@ -17,4 +17,4 @@ func init(){ } } }) -} \ No newline at end of file +} diff --git a/cmd/rr/main.go b/cmd/rr/main.go index da34a62b..18e22cdd 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -23,8 +23,8 @@ package main import ( - rr "github.com/spiral/roadrunner/cmd/rr/cmd" "github.com/sirupsen/logrus" + rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) "github.com/spiral/roadrunner/service/env" diff --git a/git b/git new file mode 100644 index 00000000..e69de29b diff --git a/server_config.go b/server_config.go index 1a24e335..51f8245b 100644 --- a/server_config.go +++ b/server_config.go @@ -35,6 +35,10 @@ type ServerConfig struct { // SetDefaults sets missing values to their default values. func (cfg *ServerConfig) SetDefaults() { + if c.Workers.Relay == "" { + c.Workers.Relay = "pipes" + } + if cfg.RelayTimeout == 0 { cfg.RelayTimeout = time.Minute } @@ -48,6 +52,21 @@ func (cfg *ServerConfig) SetDefaults() { } } +// UpscaleDurations converts duration values from nanoseconds to seconds. +func (cfg *ServerConfig) UpscaleDurations() { + if cfg.RelayTimeout < time.Microsecond { + cfg.RelayTimeout = time.Second * time.Duration(cfg.RelayTimeout.Nanoseconds()) + } + + if cfg.Pool.AllocateTimeout < time.Microsecond { + cfg.Pool.AllocateTimeout = time.Second * time.Duration(cfg.Pool.AllocateTimeout.Nanoseconds()) + } + + if cfg.Pool.DestroyTimeout < time.Microsecond { + cfg.Pool.DestroyTimeout = time.Second * time.Duration(cfg.Pool.DestroyTimeout.Nanoseconds()) + } +} + // Differs returns true if configuration has changed but ignores pool or cmd changes. func (cfg *ServerConfig) Differs(new *ServerConfig) bool { return cfg.Relay != new.Relay || cfg.RelayTimeout != new.RelayTimeout diff --git a/service/env/environment.go b/service/env/environment.go index d095009c..8e89d2c8 100644 --- a/service/env/environment.go +++ b/service/env/environment.go @@ -8,4 +8,4 @@ type Environment interface { // SetEnv sets or creates environment value. SetEnv(key, value string) -} \ No newline at end of file +} diff --git a/service/env/service_test.go b/service/env/service_test.go index 10159857..5b148207 100644 --- a/service/env/service_test.go +++ b/service/env/service_test.go @@ -23,15 +23,14 @@ func Test_Extend(t *testing.T) { assert.Equal(t, "value", values["key"]) } - func Test_Set(t *testing.T) { s := NewService(map[string]string{"rr": "version"}) s.Init(&Config{Values: map[string]string{"key": "value"}}) assert.Len(t, s.values, 2) - s.SetEnv("key","value-new") - s.SetEnv("other","new") + s.SetEnv("key", "value-new") + s.SetEnv("other", "new") values, err := s.GetEnv() assert.NoError(t, err) @@ -39,4 +38,4 @@ func Test_Set(t *testing.T) { assert.Equal(t, "version", values["rr"]) assert.Equal(t, "value-new", values["key"]) assert.Equal(t, "new", values["other"]) -} \ No newline at end of file +} diff --git a/service/http/service_test.go b/service/http/service_test.go index 4e572335..9a5a3a9b 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -6,6 +6,7 @@ import ( "github.com/sirupsen/logrus/hooks/test" "github.com/spiral/roadrunner" "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/service/env" "github.com/spiral/roadrunner/service/rpc" "github.com/stretchr/testify/assert" "io/ioutil" @@ -13,7 +14,6 @@ import ( "os" "testing" "time" - "github.com/spiral/roadrunner/service/env" ) type testCfg struct { diff --git a/service/rpc/service.go b/service/rpc/service.go index 9cd32755..14e34319 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -3,9 +3,9 @@ package rpc import ( "errors" "github.com/spiral/goridge" + "github.com/spiral/roadrunner/service/env" "net/rpc" "sync" - "github.com/spiral/roadrunner/service/env" ) const ( @@ -16,6 +16,7 @@ const ( // rpc server connection. EnvKey = "RR_RPC" ) + // Service is RPC service. type Service struct { cfg *Config diff --git a/service/rpc/service_test.go b/service/rpc/service_test.go index e47e9cdd..59e0e05d 100644 --- a/service/rpc/service_test.go +++ b/service/rpc/service_test.go @@ -30,7 +30,7 @@ func Test_RegisterNotConfigured(t *testing.T) { func Test_Enabled(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"},nil) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -38,7 +38,7 @@ func Test_Enabled(t *testing.T) { func Test_StopNonServing(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"},nil) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -47,7 +47,7 @@ func Test_StopNonServing(t *testing.T) { func Test_Serve_Errors(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"},nil) + ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -60,7 +60,7 @@ func Test_Serve_Errors(t *testing.T) { func Test_Serve_Client(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"},nil) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"}, nil) assert.NoError(t, err) assert.True(t, ok) diff --git a/service/static/config.go b/service/static/config.go index 0ec1c8d8..be0ac3ed 100644 --- a/service/static/config.go +++ b/service/static/config.go @@ -1,11 +1,11 @@ package static import ( + "fmt" "github.com/spiral/roadrunner/service" "os" "path" "strings" - "fmt" ) // Config describes file location and controls access to them. -- cgit v1.2.3 From 7dae5ddd0dc0e005fba1cdb5a2ef8afe3b61b6fb Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 14:45:23 +0300 Subject: minor config improvements --- server_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server_config.go b/server_config.go index 51f8245b..1d8c281c 100644 --- a/server_config.go +++ b/server_config.go @@ -35,8 +35,8 @@ type ServerConfig struct { // SetDefaults sets missing values to their default values. func (cfg *ServerConfig) SetDefaults() { - if c.Workers.Relay == "" { - c.Workers.Relay = "pipes" + if cfg.Relay == "" { + cfg.Relay = "pipes" } if cfg.RelayTimeout == 0 { -- cgit v1.2.3 From 6f70e31df4a88b85e576789ebe4fee6b5fc12d86 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 14:52:56 +0300 Subject: minor config improvements --- service/http/config.go | 6 +++--- service/http/service_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/service/http/config.go b/service/http/config.go index 2cfe1ba2..5be42ae6 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -35,13 +35,13 @@ func (c *Config) Hydrate(cfg service.Config) error { return nil } - c.Workers.SetDefaults() - c.Workers.UpscaleDurations() - if err := c.Valid(); err != nil { return err } + c.Workers.SetDefaults() + c.Workers.UpscaleDurations() + return nil } diff --git a/service/http/service_test.go b/service/http/service_test.go index 9a5a3a9b..8dab7cd4 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -49,7 +49,7 @@ func Test_Service_NoConfig(t *testing.T) { c := service.NewContainer(logger) c.Register(ID, &Service{}) - assert.Error(t, c.Init(&testCfg{httpCfg: `{}`})) + assert.Error(t, c.Init(&testCfg{httpCfg: `{"Enable":true}`})) s, st := c.Get(ID) assert.NotNil(t, s) -- cgit v1.2.3 From 5dcbd1fd465956ee377c67f3b5d5a17701af235a Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:11:55 +0300 Subject: more tests --- server_config.go | 4 ++++ server_config_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ service/env/service.go | 6 +++--- service/env/service_test.go | 10 ++++++++++ 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 -- cgit v1.2.3 From 8fcbecfdbc6630e0bd2a8ccc417bc9a2f3b20fb0 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:13:31 +0300 Subject: Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a980efab..51088fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ CHANGELOG ========= -v1.2.0 +v1.2.0 (10.09.2018) ------- - added ability to request `*logrus.Logger`, `logrus.StdLogger`, `logrus.FieldLogger` dependency in container -- cgit v1.2.3 From 0ac924d4025e60851dfd2c8989d1f4fb02119715 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:24:14 +0300 Subject: more tests --- service/http/rpc_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go index c392b060..32bb776c 100644 --- a/service/http/rpc_test.go +++ b/service/http/rpc_test.go @@ -177,3 +177,10 @@ func Test_Workers(t *testing.T) { assert.Equal(t, *ss.rr.Workers()[0].Pid, r.Workers[0].Pid) } + +func Test_Errors(t *testing.T) { + r := &rpcServer{nil} + + assert.Error(t, r.Reset(true, nil)) + assert.Error(t, r.Workers(true, nil)) +} -- cgit v1.2.3 From 9573091c7f0603c1d52a1180852d359feff7d99d Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:33:08 +0300 Subject: more tests --- service/http/handler_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++ service/http/rpc.go | 4 +-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/service/http/handler_test.go b/service/http/handler_test.go index 59a4c7c0..b82fc938 100644 --- a/service/http/handler_test.go +++ b/service/http/handler_test.go @@ -14,6 +14,7 @@ import ( "strings" "testing" "time" + "net/http/httptest" ) // get request and return body @@ -63,6 +64,63 @@ func TestServer_Echo(t *testing.T) { assert.Equal(t, "WORLD", body) } +func Test_HandlerErrors(t *testing.T) { + st := &Handler{ + cfg: &Config{ + MaxRequest: 1024, + Uploads: &UploadsConfig{ + Dir: os.TempDir(), + Forbid: []string{}, + }, + }, + rr: roadrunner.NewServer(&roadrunner.ServerConfig{ + Command: "php ../../php-src/tests/http/client.php echo pipes", + Relay: "pipes", + Pool: &roadrunner.Config{ + NumWorkers: 1, + AllocateTimeout: 10000000, + DestroyTimeout: 10000000, + }, + }), + } + + wr := httptest.NewRecorder() + rq := httptest.NewRequest("POST", "/", bytes.NewBuffer([]byte("data"))) + + st.ServeHTTP(wr, rq) + assert.Equal(t, 500, wr.Code) +} + +func Test_Handler_JSON_error(t *testing.T) { + st := &Handler{ + cfg: &Config{ + MaxRequest: 1024, + Uploads: &UploadsConfig{ + Dir: os.TempDir(), + Forbid: []string{}, + }, + }, + rr: roadrunner.NewServer(&roadrunner.ServerConfig{ + Command: "php ../../php-src/tests/http/client.php echo pipes", + Relay: "pipes", + Pool: &roadrunner.Config{ + NumWorkers: 1, + AllocateTimeout: 10000000, + DestroyTimeout: 10000000, + }, + }), + } + + wr := httptest.NewRecorder() + rq := httptest.NewRequest("POST", "/", bytes.NewBuffer([]byte("{sd"))) + rq.Header.Add("Content-Type","application/json") + rq.Header.Add("Content-Size","3") + + st.ServeHTTP(wr, rq) + assert.Equal(t, 500, wr.Code) +} + + func TestServer_Headers(t *testing.T) { st := &Handler{ cfg: &Config{ diff --git a/service/http/rpc.go b/service/http/rpc.go index aebc5903..9dfe718e 100644 --- a/service/http/rpc.go +++ b/service/http/rpc.go @@ -29,7 +29,7 @@ type Worker struct { // Reset resets underlying RR worker pool and restarts all of it's workers. func (rpc *rpcServer) Reset(reset bool, r *string) error { - if rpc.svc.srv == nil { + if rpc.svc == nil || rpc.svc.srv == nil { return errors.New("http server is not running") } @@ -39,7 +39,7 @@ func (rpc *rpcServer) Reset(reset bool, r *string) error { // Workers returns list of active workers and their stats. func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { - if rpc.svc.srv == nil { + if rpc.svc == nil || rpc.svc.srv == nil { return errors.New("http server is not running") } -- cgit v1.2.3 From 562464f605a013b4ab1d524b68e3668b71f2a0e3 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:34:22 +0300 Subject: update CHANGELOG --- CHANGELOG.md | 1 + build.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51088fb8..2cf8fdce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ in container - `rr.Verbose` and `rr.Debug` are not public - rpc service now exposes it's address to underlying workers to simplify the connection - env service construction has been simplified in order to unify it with other services +- more tests v1.1.1 (26.07.2018) ------- diff --git a/build.sh b/build.sh index 34dc79f6..0f7b8ef3 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ cd $(dirname "${BASH_SOURCE[0]}") OD="$(pwd)" # Pushes application version into the build information. -RR_VERSION=1.1.1 +RR_VERSION=1.2.0 # Hardcode some values to the core package LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}" -- cgit v1.2.3 From 46a06a4d104802fb4271e06da487f74f23edd10c Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 10 Sep 2018 15:38:17 +0300 Subject: update CHANGELOG --- service/rpc/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/rpc/service.go b/service/rpc/service.go index d8c2b9d5..3ea6c5fc 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -14,7 +14,7 @@ const ( // rrKey defines environment key to be used to store information about // rpc server connection. - envKey = "rr-rpc" + envKey = "rr_rpc" ) // Service is RPC service. -- cgit v1.2.3