diff options
author | Valery Piashchynski <[email protected]> | 2021-06-14 16:39:02 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-14 16:39:02 +0300 |
commit | 75ab1e16c64cfd0a6424fe4c546fdbc5e1b992dd (patch) | |
tree | 1e9a910071d20021ad0f7ef4fe6099bac6a341ef /tests/plugins/kv | |
parent | dc8ed203c247afd684f198ebbac103a10bfad72a (diff) |
- Rework redis with ws plugins
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins/kv')
-rw-r--r-- | tests/plugins/kv/configs/.rr-redis-global.yaml | 14 | ||||
-rw-r--r-- | tests/plugins/kv/configs/.rr-redis-no-config.yaml | 10 | ||||
-rw-r--r-- | tests/plugins/kv/storage_plugin_test.go | 141 |
3 files changed, 164 insertions, 1 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) |