summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-14 16:39:02 +0300
committerValery Piashchynski <[email protected]>2021-06-14 16:39:02 +0300
commit75ab1e16c64cfd0a6424fe4c546fdbc5e1b992dd (patch)
tree1e9a910071d20021ad0f7ef4fe6099bac6a341ef /tests
parentdc8ed203c247afd684f198ebbac103a10bfad72a (diff)
- Rework redis with ws plugins
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/kv/configs/.rr-redis-global.yaml14
-rw-r--r--tests/plugins/kv/configs/.rr-redis-no-config.yaml10
-rw-r--r--tests/plugins/kv/storage_plugin_test.go141
-rw-r--r--tests/plugins/redis/plugin1.go6
-rw-r--r--tests/plugins/websockets/websocket_plugin_test.go7
5 files changed, 175 insertions, 3 deletions
diff --git a/tests/plugins/kv/configs/.rr-redis-global.yaml b/tests/plugins/kv/configs/.rr-redis-global.yaml
new file mode 100644
index 00000000..d2e8aefe
--- /dev/null
+++ b/tests/plugins/kv/configs/.rr-redis-global.yaml
@@ -0,0 +1,14 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+
+logs:
+ mode: development
+ level: error
+
+redis-rr:
+ addrs:
+ - 'localhost:6379'
+
+kv:
+ redis-rr:
+ driver: redis
diff --git a/tests/plugins/kv/configs/.rr-redis-no-config.yaml b/tests/plugins/kv/configs/.rr-redis-no-config.yaml
new file mode 100644
index 00000000..9cf06374
--- /dev/null
+++ b/tests/plugins/kv/configs/.rr-redis-no-config.yaml
@@ -0,0 +1,10 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+
+logs:
+ mode: development
+ level: error
+
+kv:
+ redis-rr:
+ driver: redis
diff --git a/tests/plugins/kv/storage_plugin_test.go b/tests/plugins/kv/storage_plugin_test.go
index fd8a58cf..e7e7735a 100644
--- a/tests/plugins/kv/storage_plugin_test.go
+++ b/tests/plugins/kv/storage_plugin_test.go
@@ -18,8 +18,8 @@ import (
"github.com/spiral/roadrunner/v2/plugins/kv/drivers/boltdb"
"github.com/spiral/roadrunner/v2/plugins/kv/drivers/memcached"
"github.com/spiral/roadrunner/v2/plugins/kv/drivers/memory"
- "github.com/spiral/roadrunner/v2/plugins/kv/drivers/redis"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/plugins/redis"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/stretchr/testify/assert"
)
@@ -158,6 +158,7 @@ func TestBoltDb(t *testing.T) {
&boltdb.Plugin{},
&rpcPlugin.Plugin{},
&logger.ZapLogger{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -373,6 +374,7 @@ func TestMemcached(t *testing.T) {
&memcached.Plugin{},
&rpcPlugin.Plugin{},
&logger.ZapLogger{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -801,6 +803,143 @@ func TestRedis(t *testing.T) {
&redis.Plugin{},
&rpcPlugin.Plugin{},
&logger.ZapLogger{},
+ &memory.Plugin{},
+ )
+ 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)
+
+ stopCh := make(chan struct{}, 1)
+
+ 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 <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 1)
+ t.Run("REDIS", testRPCMethodsRedis)
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func TestRedisGlobalSection(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-redis-global.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &kv.Plugin{},
+ &redis.Plugin{},
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &memory.Plugin{},
+ )
+ 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)
+
+ stopCh := make(chan struct{}, 1)
+
+ 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 <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 1)
+ t.Run("REDIS", testRPCMethodsRedis)
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func TestRedisNoConfig(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-redis-no-config.yaml", // should be used default
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &kv.Plugin{},
+ &redis.Plugin{},
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
diff --git a/tests/plugins/redis/plugin1.go b/tests/plugins/redis/plugin1.go
index e50213e5..68da1394 100644
--- a/tests/plugins/redis/plugin1.go
+++ b/tests/plugins/redis/plugin1.go
@@ -14,8 +14,10 @@ type Plugin1 struct {
}
func (p *Plugin1) Init(redis redisPlugin.Redis) error {
- p.redisClient = redis.GetClient()
- return nil
+ var err error
+ p.redisClient, err = redis.RedisClient("redis")
+
+ return err
}
func (p *Plugin1) Serve() chan error {
diff --git a/tests/plugins/websockets/websocket_plugin_test.go b/tests/plugins/websockets/websocket_plugin_test.go
index 3ef144eb..88828c5a 100644
--- a/tests/plugins/websockets/websocket_plugin_test.go
+++ b/tests/plugins/websockets/websocket_plugin_test.go
@@ -20,6 +20,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/plugins/memory"
"github.com/spiral/roadrunner/v2/plugins/redis"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -45,6 +46,7 @@ func TestBroadcastInit(t *testing.T) {
&redis.Plugin{},
&websockets.Plugin{},
&httpPlugin.Plugin{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -153,6 +155,7 @@ func TestWSRedisAndMemory(t *testing.T) {
&redis.Plugin{},
&websockets.Plugin{},
&httpPlugin.Plugin{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -446,6 +449,7 @@ func TestWSMemoryDeny(t *testing.T) {
&redis.Plugin{},
&websockets.Plugin{},
&httpPlugin.Plugin{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -573,6 +577,7 @@ func TestWSMemoryStop(t *testing.T) {
&redis.Plugin{},
&websockets.Plugin{},
&httpPlugin.Plugin{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -665,6 +670,7 @@ func TestWSMemoryOk(t *testing.T) {
&redis.Plugin{},
&websockets.Plugin{},
&httpPlugin.Plugin{},
+ &memory.Plugin{},
)
assert.NoError(t, err)
@@ -853,6 +859,7 @@ func publish2(t *testing.T, command string, broker string, topics ...string) {
assert.NoError(t, err)
assert.True(t, ret.Ok)
}
+
func messageWS(command string, broker string, payload []byte, topics ...string) *websocketsv1.Message {
return &websocketsv1.Message{
Topics: topics,