diff options
author | Wolfy-J <[email protected]> | 2019-06-27 13:11:41 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-06-27 13:11:41 +0300 |
commit | c4a260cacc43bd8c5b87cce890ae582124ef3509 (patch) | |
tree | f9e05b0287d03d981ace0ff8b46ac20350419c0a | |
parent | b386ea186c7a5dc132b2e542b162c8cf75058636 (diff) |
rpc test
-rw-r--r-- | service/metrics/rpc_test.go | 57 | ||||
-rw-r--r-- | service/metrics/service_test.go | 6 |
2 files changed, 63 insertions, 0 deletions
diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go index 1abe097a..9668c203 100644 --- a/service/metrics/rpc_test.go +++ b/service/metrics/rpc_test.go @@ -1 +1,58 @@ package metrics + +import ( + "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus/hooks/test" + "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/service/rpc" + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func Test_Set_RPC_Metric(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"}`, + metricsCfg: `{ + "address": "localhost:2112", + "collect":{ + "user_gauge_2":{ + "type": "gauge" + } + } + + }`})) + + s, _ := c.Get(ID) + assert.NotNil(t, s) + + s2, _ := c.Get(rpc.ID) + rs := s2.(*rpc.Service) + + assert.True(t, s.(*Service).Enabled()) + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + client, err := rs.Client() + assert.NoError(t, err) + + var ok bool + assert.NoError(t, client.Call("metrics.Set", Metric{ + Name: "user_gauge_2", + Value: 100.0, + }, &ok)) + assert.True(t, ok) + + out, _, err := get("http://localhost:2112/metrics") + assert.NoError(t, err) + assert.Contains(t, out, "user_gauge_2 100") +} diff --git a/service/metrics/service_test.go b/service/metrics/service_test.go index 513b3042..892c9e30 100644 --- a/service/metrics/service_test.go +++ b/service/metrics/service_test.go @@ -6,6 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/service/rpc" "github.com/stretchr/testify/assert" "io/ioutil" "net/http" @@ -14,6 +15,7 @@ import ( ) type testCfg struct { + rpcCfg string metricsCfg string target string } @@ -23,6 +25,10 @@ func (cfg *testCfg) Get(name string) service.Config { return &testCfg{target: cfg.metricsCfg} } + if name == rpc.ID { + return &testCfg{target: cfg.rpcCfg} + } + return nil } |