diff options
author | Valery Piashchynski <[email protected]> | 2020-11-04 15:32:55 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-11-04 15:32:55 +0300 |
commit | e0a0c0d31cf9724754c63c67865403af7fceb1a4 (patch) | |
tree | 3c7fcde78a280d8058c38816931c8b15d1779c8e /plugins/rpc/tests/plugin2.go | |
parent | edc45b3e24afdb5e56e74ffbbbd50e0e3b04922b (diff) |
Update structure, add tests for RPC
Diffstat (limited to 'plugins/rpc/tests/plugin2.go')
-rw-r--r-- | plugins/rpc/tests/plugin2.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/plugins/rpc/tests/plugin2.go b/plugins/rpc/tests/plugin2.go new file mode 100644 index 00000000..feeae4af --- /dev/null +++ b/plugins/rpc/tests/plugin2.go @@ -0,0 +1,54 @@ +package tests + +import ( + "net" + "net/rpc" + "time" + + "github.com/spiral/errors" + "github.com/spiral/goridge/v2" +) + +// plugin2 makes a call to the plugin1 via RPC +// this is just a simulation of external call FOR TEST +// you don't need to do such things :) +type Plugin2 struct { +} + +func (p2 *Plugin2) Init() error { + return nil +} + +func (p2 *Plugin2) Serve() chan error { + errCh := make(chan error, 1) + + go func() { + time.Sleep(time.Second * 3) + + conn, err := net.Dial("tcp", "127.0.0.1:6001") + if err != nil { + errCh <- err + return + } + client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn)) + var ret string + err = client.Call("rpc_test.plugin1.Hello", "Valery", &ret) + if err != nil { + errCh <- err + return + } + if ret != "Hello, username: Valery" { + errCh <- errors.E("wrong response") + return + } + // to stop exec + errCh <- errors.E(errors.Disabled) + return + }() + + return errCh +} + +func (p2 *Plugin2) Stop() error { + return nil +} |