summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-21 14:24:45 +0300
committerGitHub <[email protected]>2020-12-21 14:24:45 +0300
commit8543980775e5f8b12e5e200a0764052cdb4350a5 (patch)
treec1c6dff8e6bd81bcf51d608c5ed935702911ae81 /plugins
parentfd6e9cc403fc0c3857dcf29768429a374bd85636 (diff)
parent7b32b6b93576ec72b4b7fdf2068e655f869e9cf8 (diff)
Merge pull request #453 from spiral/plugin/redis
Plugin/redis
Diffstat (limited to 'plugins')
-rw-r--r--plugins/checker/plugin.go4
-rwxr-xr-xplugins/config/configurer.go19
-rwxr-xr-xplugins/config/plugin.go41
-rwxr-xr-xplugins/config/tests/plugin1.go6
-rw-r--r--plugins/headers/plugin.go4
-rw-r--r--plugins/http/plugin.go6
-rw-r--r--plugins/http/tests/plugin1.go8
-rw-r--r--plugins/http/tests/plugin_middleware.go10
-rw-r--r--plugins/informer/tests/test_plugin.go6
-rw-r--r--plugins/logger/plugin.go4
-rw-r--r--plugins/logger/tests/plugin.go6
-rw-r--r--plugins/metrics/plugin.go4
-rw-r--r--plugins/metrics/tests/plugin1.go6
-rw-r--r--plugins/redis/config.go32
-rw-r--r--plugins/redis/plugin.go75
-rw-r--r--plugins/redis/tests/plugin1.go43
-rw-r--r--plugins/redis/tests/redis_plugin_test.go124
-rw-r--r--plugins/reload/plugin.go4
-rw-r--r--plugins/resetter/tests/test_plugin.go6
-rwxr-xr-xplugins/rpc/plugin.go2
-rw-r--r--plugins/rpc/tests/plugin1.go6
-rw-r--r--plugins/server/plugin.go8
-rw-r--r--plugins/server/tests/plugin_pipes.go8
-rw-r--r--plugins/server/tests/plugin_sockets.go8
-rw-r--r--plugins/server/tests/plugin_tcp.go8
-rw-r--r--plugins/static/plugin.go4
26 files changed, 344 insertions, 108 deletions
diff --git a/plugins/checker/plugin.go b/plugins/checker/plugin.go
index e6250697..e3e7834a 100644
--- a/plugins/checker/plugin.go
+++ b/plugins/checker/plugin.go
@@ -9,9 +9,9 @@ import (
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/spiral/endure"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
"github.com/spiral/roadrunner/v2/interfaces/status"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
const (
@@ -26,7 +26,7 @@ type Plugin struct {
cfg *Config
}
-func (c *Plugin) Init(log log.Logger, cfg config.Configurer) error {
+func (c *Plugin) Init(log log.Logger, cfg config2.Configurer) error {
const op = errors.Op("status plugin init")
err := cfg.UnmarshalKey(PluginName, &c.cfg)
if err != nil {
diff --git a/plugins/config/configurer.go b/plugins/config/configurer.go
deleted file mode 100755
index 00010eae..00000000
--- a/plugins/config/configurer.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package config
-
-type Configurer interface {
- // UnmarshalKey reads configuration section into configuration object.
- //
- // func (h *HttpService) Init(cp config.Configurer) error {
- // h.config := &HttpConfig{}
- // if err := configProvider.UnmarshalKey("http", h.config); err != nil {
- // return err
- // }
- // }
- UnmarshalKey(name string, out interface{}) error
-
- // Get used to get config section
- Get(name string) interface{}
-
- // Has checks if config section exists.
- Has(name string) bool
-}
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
index 2555d28a..4cde314d 100755
--- a/plugins/config/plugin.go
+++ b/plugins/config/plugin.go
@@ -1,17 +1,18 @@
package config
import (
+ "bytes"
"errors"
- "fmt"
"strings"
"github.com/spf13/viper"
)
type Viper struct {
- viper *viper.Viper
- Path string
- Prefix string
+ viper *viper.Viper
+ Path string
+ Prefix string
+ ReadInCfg []byte
}
// Inits config provider.
@@ -32,17 +33,16 @@ func (v *Viper) Init() error {
v.viper.SetConfigFile(v.Path)
v.viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+ if v.ReadInCfg != nil {
+ return v.viper.ReadConfig(bytes.NewBuffer(v.ReadInCfg))
+ }
return v.viper.ReadInConfig()
}
// Overwrite overwrites existing config with provided values
-func (v *Viper) Overwrite(values map[string]string) error {
+func (v *Viper) Overwrite(values map[string]interface{}) error {
if len(values) != 0 {
- for _, flag := range values {
- key, value, err := parseFlag(flag)
- if err != nil {
- return err
- }
+ for key, value := range values {
v.viper.Set(key, value)
}
}
@@ -68,24 +68,3 @@ func (v *Viper) Get(name string) interface{} {
func (v *Viper) Has(name string) bool {
return v.viper.IsSet(name)
}
-
-func parseFlag(flag string) (string, string, error) {
- if !strings.Contains(flag, "=") {
- return "", "", fmt.Errorf("invalid flag `%s`", flag)
- }
-
- parts := strings.SplitN(strings.TrimLeft(flag, " \"'`"), "=", 2)
-
- return strings.Trim(parts[0], " \n\t"), parseValue(strings.Trim(parts[1], " \n\t")), nil
-}
-
-func parseValue(value string) string {
- escape := []rune(value)[0]
-
- if escape == '"' || escape == '\'' || escape == '`' {
- value = strings.Trim(value, string(escape))
- value = strings.ReplaceAll(value, fmt.Sprintf("\\%s", string(escape)), string(escape))
- }
-
- return value
-}
diff --git a/plugins/config/tests/plugin1.go b/plugins/config/tests/plugin1.go
index a276c15f..7b5d6bd8 100755
--- a/plugins/config/tests/plugin1.go
+++ b/plugins/config/tests/plugin1.go
@@ -4,7 +4,7 @@ import (
"errors"
"time"
- "github.com/spiral/roadrunner/v2/plugins/config"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
)
// ReloadConfig is a Reload configuration point.
@@ -23,11 +23,11 @@ type ServiceConfig struct {
}
type Foo struct {
- configProvider config.Configurer
+ configProvider config2.Configurer
}
// Depends on S2 and DB (S3 in the current case)
-func (f *Foo) Init(p config.Configurer) error {
+func (f *Foo) Init(p config2.Configurer) error {
f.configProvider = p
return nil
}
diff --git a/plugins/headers/plugin.go b/plugins/headers/plugin.go
index f1c6e6f3..e16f6187 100644
--- a/plugins/headers/plugin.go
+++ b/plugins/headers/plugin.go
@@ -5,7 +5,7 @@ import (
"strconv"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/plugins/config"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
)
// ID contains default service name.
@@ -20,7 +20,7 @@ type Plugin struct {
// Init must return configure service and return true if service hasStatus enabled. Must return error in case of
// misconfiguration. Services must not be used without proper configuration pushed first.
-func (s *Plugin) Init(cfg config.Configurer) error {
+func (s *Plugin) Init(cfg config2.Configurer) error {
const op = errors.Op("headers plugin init")
err := cfg.UnmarshalKey(RootPluginName, &s.cfg)
if err != nil {
diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go
index 460263f6..a883735a 100644
--- a/plugins/http/plugin.go
+++ b/plugins/http/plugin.go
@@ -15,6 +15,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/spiral/endure"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/events"
"github.com/spiral/roadrunner/v2/interfaces/log"
"github.com/spiral/roadrunner/v2/interfaces/pool"
@@ -22,7 +23,6 @@ import (
"github.com/spiral/roadrunner/v2/interfaces/status"
"github.com/spiral/roadrunner/v2/interfaces/worker"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
- "github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/http/attributes"
"github.com/spiral/roadrunner/v2/util"
"golang.org/x/net/http2"
@@ -49,7 +49,7 @@ type middleware map[string]Middleware
type Plugin struct {
sync.Mutex
- configurer config.Configurer
+ configurer config2.Configurer
server server.Server
log log.Logger
@@ -80,7 +80,7 @@ func (s *Plugin) AddListener(listener events.EventListener) {
// 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 *Plugin) Init(cfg config.Configurer, log log.Logger, server server.Server) error {
+func (s *Plugin) Init(cfg config2.Configurer, log log.Logger, server server.Server) error {
const op = errors.Op("http Init")
err := cfg.UnmarshalKey(PluginName, &s.cfg)
if err != nil {
diff --git a/plugins/http/tests/plugin1.go b/plugins/http/tests/plugin1.go
index 1cbca744..7d1f32a1 100644
--- a/plugins/http/tests/plugin1.go
+++ b/plugins/http/tests/plugin1.go
@@ -1,12 +1,14 @@
package tests
-import "github.com/spiral/roadrunner/v2/plugins/config"
+import (
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
+)
type Plugin1 struct {
- config config.Configurer
+ config config2.Configurer
}
-func (p1 *Plugin1) Init(cfg config.Configurer) error {
+func (p1 *Plugin1) Init(cfg config2.Configurer) error {
p1.config = cfg
return nil
}
diff --git a/plugins/http/tests/plugin_middleware.go b/plugins/http/tests/plugin_middleware.go
index de829d34..224d4117 100644
--- a/plugins/http/tests/plugin_middleware.go
+++ b/plugins/http/tests/plugin_middleware.go
@@ -3,14 +3,14 @@ package tests
import (
"net/http"
- "github.com/spiral/roadrunner/v2/plugins/config"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
)
type PluginMiddleware struct {
- config config.Configurer
+ config config2.Configurer
}
-func (p *PluginMiddleware) Init(cfg config.Configurer) error {
+func (p *PluginMiddleware) Init(cfg config2.Configurer) error {
p.config = cfg
return nil
}
@@ -34,10 +34,10 @@ func (p *PluginMiddleware) Name() string {
}
type PluginMiddleware2 struct {
- config config.Configurer
+ config config2.Configurer
}
-func (p *PluginMiddleware2) Init(cfg config.Configurer) error {
+func (p *PluginMiddleware2) Init(cfg config2.Configurer) error {
p.config = cfg
return nil
}
diff --git a/plugins/informer/tests/test_plugin.go b/plugins/informer/tests/test_plugin.go
index 3fdefde3..80627801 100644
--- a/plugins/informer/tests/test_plugin.go
+++ b/plugins/informer/tests/test_plugin.go
@@ -4,10 +4,10 @@ import (
"context"
"time"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/server"
"github.com/spiral/roadrunner/v2/interfaces/worker"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
var testPoolConfig = poolImpl.Config{
@@ -26,11 +26,11 @@ var testPoolConfig = poolImpl.Config{
// Gauge //////////////
type Plugin1 struct {
- config config.Configurer
+ config config2.Configurer
server server.Server
}
-func (p1 *Plugin1) Init(cfg config.Configurer, server server.Server) error {
+func (p1 *Plugin1) Init(cfg config2.Configurer, server server.Server) error {
p1.config = cfg
p1.server = server
return nil
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go
index 64b77a64..ec58b7d6 100644
--- a/plugins/logger/plugin.go
+++ b/plugins/logger/plugin.go
@@ -2,8 +2,8 @@ package logger
import (
"github.com/spiral/endure"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
- "github.com/spiral/roadrunner/v2/plugins/config"
"go.uber.org/zap"
)
@@ -18,7 +18,7 @@ type ZapLogger struct {
}
// Init logger service.
-func (z *ZapLogger) Init(cfg config.Configurer) error {
+func (z *ZapLogger) Init(cfg config2.Configurer) error {
err := cfg.UnmarshalKey(PluginName, &z.cfg)
if err != nil {
return err
diff --git a/plugins/logger/tests/plugin.go b/plugins/logger/tests/plugin.go
index 32238f63..4095e59d 100644
--- a/plugins/logger/tests/plugin.go
+++ b/plugins/logger/tests/plugin.go
@@ -2,16 +2,16 @@ package tests
import (
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
type Plugin struct {
- config config.Configurer
+ config config2.Configurer
log log.Logger
}
-func (p1 *Plugin) Init(cfg config.Configurer, log log.Logger) error {
+func (p1 *Plugin) Init(cfg config2.Configurer, log log.Logger) error {
p1.config = cfg
p1.log = log
return nil
diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go
index c115826b..956166ee 100644
--- a/plugins/metrics/plugin.go
+++ b/plugins/metrics/plugin.go
@@ -11,9 +11,9 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spiral/endure"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
"github.com/spiral/roadrunner/v2/interfaces/metrics"
- "github.com/spiral/roadrunner/v2/plugins/config"
"golang.org/x/sys/cpu"
)
@@ -40,7 +40,7 @@ type Plugin struct {
}
// Init service.
-func (m *Plugin) Init(cfg config.Configurer, log log.Logger) error {
+func (m *Plugin) Init(cfg config2.Configurer, log log.Logger) error {
const op = errors.Op("Metrics Init")
err := cfg.UnmarshalKey(PluginName, &m.cfg)
if err != nil {
diff --git a/plugins/metrics/tests/plugin1.go b/plugins/metrics/tests/plugin1.go
index b48c415d..08dd2593 100644
--- a/plugins/metrics/tests/plugin1.go
+++ b/plugins/metrics/tests/plugin1.go
@@ -2,15 +2,15 @@ package tests
import (
"github.com/prometheus/client_golang/prometheus"
- "github.com/spiral/roadrunner/v2/plugins/config"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
)
// Gauge //////////////
type Plugin1 struct {
- config config.Configurer
+ config config2.Configurer
}
-func (p1 *Plugin1) Init(cfg config.Configurer) error {
+func (p1 *Plugin1) Init(cfg config2.Configurer) error {
p1.config = cfg
return nil
}
diff --git a/plugins/redis/config.go b/plugins/redis/config.go
new file mode 100644
index 00000000..ebcefed1
--- /dev/null
+++ b/plugins/redis/config.go
@@ -0,0 +1,32 @@
+package redis
+
+import "time"
+
+type Config struct {
+ Addrs []string `yaml:"addrs"`
+ DB int `yaml:"db"`
+ Username string `yaml:"username"`
+ Password string `yaml:"password"`
+ MasterName string `yaml:"master_name"`
+ SentinelPassword string `yaml:"sentinel_password"`
+ RouteByLatency bool `yaml:"route_by_latency"`
+ RouteRandomly bool `yaml:"route_randomly"`
+ MaxRetries int `yaml:"max_retries"`
+ DialTimeout time.Duration `yaml:"dial_timeout"`
+ MinRetryBackoff time.Duration `yaml:"min_retry_backoff"`
+ MaxRetryBackoff time.Duration `yaml:"max_retry_backoff"`
+ PoolSize int `yaml:"pool_size"`
+ MinIdleConns int `yaml:"min_idle_conns"`
+ MaxConnAge time.Duration `yaml:"max_conn_age"`
+ ReadTimeout time.Duration `yaml:"read_timeout"`
+ WriteTimeout time.Duration `yaml:"write_timeout"`
+ PoolTimeout time.Duration `yaml:"pool_timeout"`
+ IdleTimeout time.Duration `yaml:"idle_timeout"`
+ IdleCheckFreq time.Duration `yaml:"idle_check_freq"`
+ ReadOnly bool `yaml:"read_only"`
+}
+
+// InitDefaults initializing fill config with default values
+func (s *Config) InitDefaults() {
+ s.Addrs = []string{"localhost:6379"} // default addr is pointing to local storage
+}
diff --git a/plugins/redis/plugin.go b/plugins/redis/plugin.go
new file mode 100644
index 00000000..08bb7972
--- /dev/null
+++ b/plugins/redis/plugin.go
@@ -0,0 +1,75 @@
+package redis
+
+import (
+ "github.com/go-redis/redis/v8"
+ "github.com/spiral/errors"
+ "github.com/spiral/roadrunner/v2/interfaces/config"
+ "github.com/spiral/roadrunner/v2/interfaces/log"
+)
+
+const PluginName = "redis"
+
+type Plugin struct {
+ // config for RR integration
+ cfg *Config
+ // logger
+ log log.Logger
+ // redis universal client
+ universalClient redis.UniversalClient
+}
+
+func (s *Plugin) GetClient() redis.UniversalClient {
+ return s.universalClient
+}
+
+func (s *Plugin) Init(cfg config.Configurer, log log.Logger) error {
+ const op = errors.Op("redis plugin init")
+ s.cfg = &Config{}
+ s.cfg.InitDefaults()
+
+ err := cfg.UnmarshalKey(PluginName, &s.cfg)
+ if err != nil {
+ return errors.E(op, errors.Disabled, err)
+ }
+
+ s.log = log
+
+ s.universalClient = redis.NewUniversalClient(&redis.UniversalOptions{
+ Addrs: s.cfg.Addrs,
+ DB: s.cfg.DB,
+ Username: s.cfg.Username,
+ Password: s.cfg.Password,
+ SentinelPassword: s.cfg.SentinelPassword,
+ MaxRetries: s.cfg.MaxRetries,
+ MinRetryBackoff: s.cfg.MaxRetryBackoff,
+ MaxRetryBackoff: s.cfg.MaxRetryBackoff,
+ DialTimeout: s.cfg.DialTimeout,
+ ReadTimeout: s.cfg.ReadTimeout,
+ WriteTimeout: s.cfg.WriteTimeout,
+ PoolSize: s.cfg.PoolSize,
+ MinIdleConns: s.cfg.MinIdleConns,
+ MaxConnAge: s.cfg.MaxConnAge,
+ PoolTimeout: s.cfg.PoolTimeout,
+ IdleTimeout: s.cfg.IdleTimeout,
+ IdleCheckFrequency: s.cfg.IdleCheckFreq,
+ ReadOnly: s.cfg.ReadOnly,
+ RouteByLatency: s.cfg.RouteByLatency,
+ RouteRandomly: s.cfg.RouteRandomly,
+ MasterName: s.cfg.MasterName,
+ })
+
+ return nil
+}
+
+func (s *Plugin) Serve() chan error {
+ errCh := make(chan error, 1)
+ return errCh
+}
+
+func (s Plugin) Stop() error {
+ return s.universalClient.Close()
+}
+
+func (s *Plugin) Name() string {
+ return PluginName
+}
diff --git a/plugins/redis/tests/plugin1.go b/plugins/redis/tests/plugin1.go
new file mode 100644
index 00000000..e19ca90a
--- /dev/null
+++ b/plugins/redis/tests/plugin1.go
@@ -0,0 +1,43 @@
+package tests
+
+import (
+ "context"
+ "time"
+
+ "github.com/go-redis/redis/v8"
+ "github.com/spiral/errors"
+ redisPlugin "github.com/spiral/roadrunner/v2/interfaces/redis"
+)
+
+type Plugin1 struct {
+ redisClient redis.UniversalClient
+}
+
+func (p *Plugin1) Init(redis redisPlugin.Redis) error {
+ p.redisClient = redis.GetClient()
+ return nil
+}
+
+func (p *Plugin1) Serve() chan error {
+ const op = errors.Op("plugin1 serve")
+ errCh := make(chan error, 1)
+ p.redisClient.Set(context.Background(), "foo", "bar", time.Minute)
+
+ stringCmd := p.redisClient.Get(context.Background(), "foo")
+ data, err := stringCmd.Result()
+ if err != nil {
+ errCh <- errors.E(op, err)
+ return errCh
+ }
+
+ if data != "bar" {
+ errCh <- errors.E(op, errors.Str("no such key"))
+ return errCh
+ }
+
+ return errCh
+}
+
+func (p *Plugin1) Stop() error {
+ return p.redisClient.Close()
+}
diff --git a/plugins/redis/tests/redis_plugin_test.go b/plugins/redis/tests/redis_plugin_test.go
new file mode 100644
index 00000000..8f8da983
--- /dev/null
+++ b/plugins/redis/tests/redis_plugin_test.go
@@ -0,0 +1,124 @@
+package tests
+
+import (
+ "fmt"
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+ "testing"
+ "time"
+
+ "github.com/alicebob/miniredis/v2"
+ "github.com/golang/mock/gomock"
+ "github.com/spiral/endure"
+ "github.com/spiral/roadrunner/v2/mocks"
+ "github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/spiral/roadrunner/v2/plugins/redis"
+ "github.com/stretchr/testify/assert"
+)
+
+func redisConfig(port string) string {
+ cfg := `
+redis:
+ addrs:
+ - 'localhost:%s'
+ master_name: ''
+ username: ''
+ password: ''
+ db: 0
+ sentinel_password: ''
+ route_by_latency: false
+ route_randomly: false
+ dial_timeout: 0
+ max_retries: 1
+ min_retry_backoff: 0
+ max_retry_backoff: 0
+ pool_size: 0
+ min_idle_conns: 0
+ max_conn_age: 0
+ read_timeout: 0
+ write_timeout: 0
+ pool_timeout: 0
+ idle_timeout: 0
+ idle_check_freq: 0
+ read_only: false
+`
+ return fmt.Sprintf(cfg, port)
+}
+
+func TestRedisInit(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ s, err := miniredis.Run()
+ if err != nil {
+ panic(err)
+ }
+ defer s.Close()
+
+ c := redisConfig(s.Port())
+
+ cfg := &config.Viper{}
+ cfg.Prefix = "rr"
+ cfg.Path = ".rr-redis.yaml"
+ cfg.ReadInCfg = []byte(c)
+
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ err = cont.RegisterAll(
+ cfg,
+ mockLogger,
+ &redis.Plugin{},
+ &Plugin1{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ tt := time.NewTimer(time.Second * 10)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ wg.Wait()
+}
diff --git a/plugins/reload/plugin.go b/plugins/reload/plugin.go
index 555ddb82..233c83a4 100644
--- a/plugins/reload/plugin.go
+++ b/plugins/reload/plugin.go
@@ -6,9 +6,9 @@ import (
"time"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
"github.com/spiral/roadrunner/v2/interfaces/resetter"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
// PluginName contains default plugin name.
@@ -25,7 +25,7 @@ type Plugin struct {
}
// Init controller service
-func (s *Plugin) Init(cfg config.Configurer, log log.Logger, res resetter.Resetter) error {
+func (s *Plugin) Init(cfg config2.Configurer, log log.Logger, res resetter.Resetter) error {
const op = errors.Op("reload plugin init")
s.cfg = &Config{}
InitDefaults(s.cfg)
diff --git a/plugins/resetter/tests/test_plugin.go b/plugins/resetter/tests/test_plugin.go
index 1d770e70..f1c09caf 100644
--- a/plugins/resetter/tests/test_plugin.go
+++ b/plugins/resetter/tests/test_plugin.go
@@ -4,9 +4,9 @@ import (
"context"
"time"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/server"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
var testPoolConfig = poolImpl.Config{
@@ -25,11 +25,11 @@ var testPoolConfig = poolImpl.Config{
// Gauge //////////////
type Plugin1 struct {
- config config.Configurer
+ config config2.Configurer
server server.Server
}
-func (p1 *Plugin1) Init(cfg config.Configurer, server server.Server) error {
+func (p1 *Plugin1) Init(cfg config2.Configurer, server server.Server) error {
p1.config = cfg
p1.server = server
return nil
diff --git a/plugins/rpc/plugin.go b/plugins/rpc/plugin.go
index 98242ade..d0dc0ff1 100755
--- a/plugins/rpc/plugin.go
+++ b/plugins/rpc/plugin.go
@@ -8,9 +8,9 @@ import (
"github.com/spiral/endure"
"github.com/spiral/errors"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
+ "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
rpc_ "github.com/spiral/roadrunner/v2/interfaces/rpc"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
// PluginName contains default plugin name.
diff --git a/plugins/rpc/tests/plugin1.go b/plugins/rpc/tests/plugin1.go
index 79e98ed4..dcb256fa 100644
--- a/plugins/rpc/tests/plugin1.go
+++ b/plugins/rpc/tests/plugin1.go
@@ -3,14 +3,14 @@ package tests
import (
"fmt"
- "github.com/spiral/roadrunner/v2/plugins/config"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
)
type Plugin1 struct {
- config config.Configurer
+ config config2.Configurer
}
-func (p1 *Plugin1) Init(cfg config.Configurer) error {
+func (p1 *Plugin1) Init(cfg config2.Configurer) error {
p1.config = cfg
return nil
}
diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go
index e6003fbc..580c1e10 100644
--- a/plugins/server/plugin.go
+++ b/plugins/server/plugin.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/events"
"github.com/spiral/roadrunner/v2/interfaces/log"
"github.com/spiral/roadrunner/v2/interfaces/pool"
@@ -16,7 +17,6 @@ import (
"github.com/spiral/roadrunner/v2/pkg/pipe"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/socket"
- "github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/util"
)
@@ -30,7 +30,7 @@ type Plugin struct {
}
// Init application provider.
-func (server *Plugin) Init(cfg config.Configurer, log log.Logger) error {
+func (server *Plugin) Init(cfg config2.Configurer, log log.Logger) error {
const op = errors.Op("Init")
err := cfg.UnmarshalKey(PluginName, &server.cfg)
if err != nil {
@@ -62,7 +62,7 @@ func (server *Plugin) Stop() error {
return nil
}
- return server.factory.Close(context.Background())
+ return server.factory.Close()
}
// CmdFactory provides worker command factory assocated with given context.
@@ -105,7 +105,7 @@ func (server *Plugin) NewWorker(ctx context.Context, env server.Env) (worker.Bas
return nil, errors.E(op, err)
}
- w, err := server.factory.SpawnWorkerWithContext(ctx, spawnCmd())
+ w, err := server.factory.SpawnWorkerWithTimeout(ctx, spawnCmd())
if err != nil {
return nil, errors.E(op, err)
}
diff --git a/plugins/server/tests/plugin_pipes.go b/plugins/server/tests/plugin_pipes.go
index 9a8a630c..f49cf6dc 100644
--- a/plugins/server/tests/plugin_pipes.go
+++ b/plugins/server/tests/plugin_pipes.go
@@ -5,12 +5,12 @@ import (
"time"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
"github.com/spiral/roadrunner/v2/pkg/payload"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/worker"
- "github.com/spiral/roadrunner/v2/plugins/config"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
)
@@ -32,12 +32,12 @@ var testPoolConfig = poolImpl.Config{
}
type Foo struct {
- configProvider config.Configurer
+ configProvider config2.Configurer
wf server.Server
pool pool.Pool
}
-func (f *Foo) Init(p config.Configurer, workerFactory server.Server) error {
+func (f *Foo) Init(p config2.Configurer, workerFactory server.Server) error {
f.configProvider = p
f.wf = workerFactory
return nil
@@ -99,7 +99,7 @@ func (f *Foo) Serve() chan error {
}
// should not be errors
- err = sw.Stop(context.Background())
+ err = sw.Stop()
if err != nil {
errCh <- err
return errCh
diff --git a/plugins/server/tests/plugin_sockets.go b/plugins/server/tests/plugin_sockets.go
index b1545718..ee971e45 100644
--- a/plugins/server/tests/plugin_sockets.go
+++ b/plugins/server/tests/plugin_sockets.go
@@ -4,21 +4,21 @@ import (
"context"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
"github.com/spiral/roadrunner/v2/pkg/payload"
"github.com/spiral/roadrunner/v2/pkg/worker"
- "github.com/spiral/roadrunner/v2/plugins/config"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
)
type Foo2 struct {
- configProvider config.Configurer
+ configProvider config2.Configurer
wf server.Server
pool pool.Pool
}
-func (f *Foo2) Init(p config.Configurer, workerFactory server.Server) error {
+func (f *Foo2) Init(p config2.Configurer, workerFactory server.Server) error {
f.configProvider = p
f.wf = workerFactory
return nil
@@ -79,7 +79,7 @@ func (f *Foo2) Serve() chan error {
}
// should not be errors
- err = sw.Stop(context.Background())
+ err = sw.Stop()
if err != nil {
errCh <- err
return errCh
diff --git a/plugins/server/tests/plugin_tcp.go b/plugins/server/tests/plugin_tcp.go
index da92288a..cdf23e21 100644
--- a/plugins/server/tests/plugin_tcp.go
+++ b/plugins/server/tests/plugin_tcp.go
@@ -4,21 +4,21 @@ import (
"context"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
"github.com/spiral/roadrunner/v2/pkg/payload"
"github.com/spiral/roadrunner/v2/pkg/worker"
- "github.com/spiral/roadrunner/v2/plugins/config"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
)
type Foo3 struct {
- configProvider config.Configurer
+ configProvider config2.Configurer
wf server.Server
pool pool.Pool
}
-func (f *Foo3) Init(p config.Configurer, workerFactory server.Server) error {
+func (f *Foo3) Init(p config2.Configurer, workerFactory server.Server) error {
f.configProvider = p
f.wf = workerFactory
return nil
@@ -79,7 +79,7 @@ func (f *Foo3) Serve() chan error {
}
// should not be errors
- err = sw.Stop(context.Background())
+ err = sw.Stop()
if err != nil {
errCh <- err
return errCh
diff --git a/plugins/static/plugin.go b/plugins/static/plugin.go
index cf5cee25..fd8d0a9c 100644
--- a/plugins/static/plugin.go
+++ b/plugins/static/plugin.go
@@ -5,8 +5,8 @@ import (
"path"
"github.com/spiral/errors"
+ config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/log"
- "github.com/spiral/roadrunner/v2/plugins/config"
)
// ID contains default service name.
@@ -27,7 +27,7 @@ type Plugin struct {
// Init must return configure service and return true if service hasStatus enabled. Must return error in case of
// misconfiguration. Services must not be used without proper configuration pushed first.
-func (s *Plugin) Init(cfg config.Configurer, log log.Logger) error {
+func (s *Plugin) Init(cfg config2.Configurer, log log.Logger) error {
const op = errors.Op("static plugin init")
err := cfg.UnmarshalKey(RootPluginName, &s.cfg)
if err != nil {