summaryrefslogtreecommitdiff
path: root/plugins/rpc
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-04 15:43:16 +0300
committerValery Piashchynski <[email protected]>2020-11-04 15:43:16 +0300
commit0304f09d7e5fa0c76b86429a654aeb366cec6391 (patch)
tree92ab0ba0f91e6668f5087eeadcfdf81a78e80e0b /plugins/rpc
parente0a0c0d31cf9724754c63c67865403af7fceb1a4 (diff)
Add rpc disabled test
Diffstat (limited to 'plugins/rpc')
-rw-r--r--plugins/rpc/tests/.rr-rpc-disabled.yaml3
-rw-r--r--plugins/rpc/tests/plugin2.go2
-rw-r--r--plugins/rpc/tests/rpc_test.go80
3 files changed, 83 insertions, 2 deletions
diff --git a/plugins/rpc/tests/.rr-rpc-disabled.yaml b/plugins/rpc/tests/.rr-rpc-disabled.yaml
new file mode 100644
index 00000000..624fb3c5
--- /dev/null
+++ b/plugins/rpc/tests/.rr-rpc-disabled.yaml
@@ -0,0 +1,3 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+ disabled: true \ No newline at end of file
diff --git a/plugins/rpc/tests/plugin2.go b/plugins/rpc/tests/plugin2.go
index feeae4af..854bf097 100644
--- a/plugins/rpc/tests/plugin2.go
+++ b/plugins/rpc/tests/plugin2.go
@@ -27,7 +27,7 @@ func (p2 *Plugin2) Serve() chan error {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
if err != nil {
- errCh <- err
+ errCh <- errors.E(errors.Serve, err)
return
}
client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
diff --git a/plugins/rpc/tests/rpc_test.go b/plugins/rpc/tests/rpc_test.go
index 85a11eec..0014cc2a 100644
--- a/plugins/rpc/tests/rpc_test.go
+++ b/plugins/rpc/tests/rpc_test.go
@@ -17,7 +17,7 @@ import (
// graph https://bit.ly/3ensdNb
func TestRpcInit(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
if err != nil {
t.Fatal(err)
}
@@ -93,3 +93,81 @@ func TestRpcInit(t *testing.T) {
}
}
}
+
+// graph https://bit.ly/3ensdNb
+func TestRpcDisabled(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = cont.Register(&Plugin1{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = cont.Register(&Plugin2{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ v := &config.Viper{}
+ v.Path = ".rr-rpc-disabled.yaml"
+ v.Prefix = "rr"
+ err = cont.Register(v)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = cont.Register(&rpc.Plugin{})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = cont.Register(&logger.ZapLogger{})
+ if err != nil {
+ t.Fatal(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)
+ tt := time.NewTimer(time.Second * 10)
+
+ for {
+ select {
+ case e := <-ch:
+ // RPC is turned off, should be and dial error
+ if errors.Is(errors.Disabled, e.Error) {
+ assert.FailNow(t, "should not be disabled error")
+ }
+ assert.Error(t, e.Error)
+ err = cont.Stop()
+ assert.Error(t, e.Error)
+ return
+ 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())
+ }
+ assert.Fail(t, "timeout")
+ }
+ }
+}