diff options
author | Valery Piashchynski <[email protected]> | 2021-06-14 17:32:25 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-14 17:32:25 +0300 |
commit | d8c013c1f1ae58f6e75a6bea0bef90e29124df51 (patch) | |
tree | 808dfae72328887cc698fac7290c8469dedf5d2a /tests/plugins | |
parent | 9748651763415c417eaa339920cba031d418fda6 (diff) |
- Fix boltdb issues
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins')
-rw-r--r-- | tests/plugins/kv/configs/.rr-kv-bolt-no-interval.yaml | 14 | ||||
-rw-r--r-- | tests/plugins/kv/configs/.rr-kv-bolt-perms.yaml | 13 | ||||
-rw-r--r-- | tests/plugins/kv/storage_plugin_test.go | 218 |
3 files changed, 245 insertions, 0 deletions
diff --git a/tests/plugins/kv/configs/.rr-kv-bolt-no-interval.yaml b/tests/plugins/kv/configs/.rr-kv-bolt-no-interval.yaml new file mode 100644 index 00000000..f58de3e4 --- /dev/null +++ b/tests/plugins/kv/configs/.rr-kv-bolt-no-interval.yaml @@ -0,0 +1,14 @@ +rpc: + listen: tcp://127.0.0.1:6001 + + +kv: + boltdb-south: + driver: boltdb + file: "rr.db" + permissions: 755 + + boltdb-africa: + driver: boltdb + file: "africa.db" + permissions: 755 diff --git a/tests/plugins/kv/configs/.rr-kv-bolt-perms.yaml b/tests/plugins/kv/configs/.rr-kv-bolt-perms.yaml new file mode 100644 index 00000000..08b3bfad --- /dev/null +++ b/tests/plugins/kv/configs/.rr-kv-bolt-perms.yaml @@ -0,0 +1,13 @@ +rpc: + listen: tcp://127.0.0.1:6001 + + +kv: + boltdb-south: + driver: boltdb + file: "rr.db" + + boltdb-africa: + driver: boltdb + file: "africa.db" + permissions: 0777 diff --git a/tests/plugins/kv/storage_plugin_test.go b/tests/plugins/kv/storage_plugin_test.go index e7e7735a..0ded9fbd 100644 --- a/tests/plugins/kv/storage_plugin_test.go +++ b/tests/plugins/kv/storage_plugin_test.go @@ -102,6 +102,224 @@ func TestKVInit(t *testing.T) { _ = os.RemoveAll("africa.db") } +func TestKVNoInterval(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-kv-bolt-no-interval.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &boltdb.Plugin{}, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &kv.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + if err != nil { + t.Fatal(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("KvSetTest", kvSetTest) + t.Run("KvHasTest", kvHasTest) + + stopCh <- struct{}{} + + wg.Wait() + + _ = os.RemoveAll("rr.db") + _ = os.RemoveAll("africa.db") +} + +func TestKVCreateToReopenWithPerms(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-kv-bolt-perms.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &boltdb.Plugin{}, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &kv.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + if err != nil { + t.Fatal(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) + stopCh <- struct{}{} + wg.Wait() +} + +func TestKVCreateToReopenWithPerms2(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-kv-bolt-perms.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &boltdb.Plugin{}, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &kv.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + if err != nil { + t.Fatal(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("KvSetTest", kvSetTest) + t.Run("KvHasTest", kvHasTest) + + stopCh <- struct{}{} + + wg.Wait() + + _ = os.RemoveAll("rr.db") + _ = os.RemoveAll("africa.db") +} + func kvSetTest(t *testing.T) { conn, err := net.Dial("tcp", "127.0.0.1:6001") assert.NoError(t, err) |