diff options
author | Wolfy-J <[email protected]> | 2018-06-13 22:24:47 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-13 22:24:47 +0300 |
commit | df4c11fb59b8ffca369f14eededda82884ee4dad (patch) | |
tree | c59b4af544cf11008739313a54b878cc20db793d /service/http/rpc_test.go | |
parent | 235adef3eef67888e4c391b28cedadfb3f8874e3 (diff) |
more tests + rpc tests
Diffstat (limited to 'service/http/rpc_test.go')
-rw-r--r-- | service/http/rpc_test.go | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go new file mode 100644 index 00000000..ba71f7e1 --- /dev/null +++ b/service/http/rpc_test.go @@ -0,0 +1,115 @@ +package http + +import ( + "testing" + "github.com/sirupsen/logrus/hooks/test" + "github.com/sirupsen/logrus" + "github.com/spiral/roadrunner/service" + "github.com/stretchr/testify/assert" + "time" + "github.com/spiral/roadrunner/service/rpc" + "strconv" +) + +func Test_RPC(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(rpc.ID, &rpc.Service{}) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{ + rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`, + httpCfg: `{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php pid pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) + + s, _ := c.Get(ID) + ss := s.(*Service) + + s2, _ := c.Get(rpc.ID) + rs := s2.(*rpc.Service) + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + res, _, _ := get("http://localhost:6029") + assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res) + + cl, err := rs.Client() + assert.NoError(t, err) + + r := "" + assert.NoError(t, cl.Call("http.Reset", true, &r)) + assert.Equal(t, "OK", r) + + res2, _, _ := get("http://localhost:6029") + assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res2) + assert.NotEqual(t, res, res2) +} + +func Test_Workers(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(rpc.ID, &rpc.Service{}) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{ + rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`, + httpCfg: `{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php pid pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) + + s, _ := c.Get(ID) + ss := s.(*Service) + + s2, _ := c.Get(rpc.ID) + rs := s2.(*rpc.Service) + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + cl, err := rs.Client() + assert.NoError(t, err) + + r := &WorkerList{} + assert.NoError(t, cl.Call("http.Workers", true, &r)) + assert.Len(t, r.Workers, 1) + + assert.Equal(t, *ss.rr.Workers()[0].Pid, r.Workers[0].Pid) +} |