summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/http/config/http.go20
-rw-r--r--plugins/metrics/rpc.go14
-rw-r--r--plugins/rpc/plugin.go3
-rw-r--r--tests/mocks/mock_log.go10
-rwxr-xr-xtests/plugins/checker/configs/.rr-checker-init.yaml1
-rwxr-xr-xtests/plugins/config/.rr.yaml1
-rw-r--r--tests/plugins/gzip/plugin_test.go2
-rw-r--r--tests/plugins/headers/headers_plugin_test.go1
-rw-r--r--tests/plugins/http/configs/.rr-broken-pipes.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-env.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-fcgi-reqUri.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-fcgi.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-h2c.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-http.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-init.yaml2
-rw-r--r--tests/plugins/http/configs/.rr-no-http.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-resetter.yaml1
-rw-r--r--tests/plugins/informer/.rr-informer.yaml1
-rw-r--r--tests/plugins/informer/informer_test.go17
-rw-r--r--tests/plugins/kv/boltdb/configs/.rr-init.yaml1
-rw-r--r--tests/plugins/kv/memcached/configs/.rr-init.yaml1
-rw-r--r--tests/plugins/kv/memory/configs/.rr-init.yaml3
-rw-r--r--tests/plugins/metrics/.rr-test.yaml1
-rw-r--r--tests/plugins/metrics/metrics_test.go76
-rw-r--r--tests/plugins/mocks/mock_log.go150
-rw-r--r--tests/plugins/resetter/.rr-resetter.yaml3
-rw-r--r--tests/plugins/resetter/resetter_test.go21
27 files changed, 130 insertions, 206 deletions
diff --git a/plugins/http/config/http.go b/plugins/http/config/http.go
index bd689918..a8b1e8e3 100644
--- a/plugins/http/config/http.go
+++ b/plugins/http/config/http.go
@@ -146,26 +146,6 @@ func ParseCIDRs(subnets []string) (Cidrs, error) {
return c, nil
}
-// IsTrusted if api can be trusted to use X-Real-Ip, X-Forwarded-For
-func (c *HTTP) IsTrusted(ip string) bool {
- if c.Cidrs == nil {
- return false
- }
-
- i := net.ParseIP(ip)
- if i == nil {
- return false
- }
-
- for _, cird := range c.Cidrs {
- if cird.Contains(i) {
- return true
- }
- }
-
- return false
-}
-
// Valid validates the configuration.
func (c *HTTP) Valid() error {
const op = errors.Op("validation")
diff --git a/plugins/metrics/rpc.go b/plugins/metrics/rpc.go
index d7c90d39..538cdb78 100644
--- a/plugins/metrics/rpc.go
+++ b/plugins/metrics/rpc.go
@@ -26,7 +26,7 @@ type Metric struct {
// Add new metric to the designated collector.
func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
const op = errors.Op("metrics_plugin_add")
- rpc.log.Info("Adding metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
+ rpc.log.Info("adding metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
rpc.log.Error("undefined collector", "collector", m.Name)
@@ -70,14 +70,14 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
// RPC, set ok to true as return value. Need by rpc.Call reply argument
*ok = true
- rpc.log.Info("new metric successfully added", "name", m.Name, "labels", m.Labels, "value", m.Value)
+ rpc.log.Info("metric successfully added", "name", m.Name, "labels", m.Labels, "value", m.Value)
return nil
}
// Sub subtract the value from the specific metric (gauge only).
func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
const op = errors.Op("metrics_plugin_sub")
- rpc.log.Info("Subtracting value from metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
+ rpc.log.Info("subtracting value from metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
rpc.log.Error("undefined collector", "name", m.Name, "value", m.Value, "labels", m.Labels)
@@ -107,7 +107,7 @@ func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
default:
return errors.E(op, errors.Errorf("collector `%s` does not support method `Sub`", m.Name))
}
- rpc.log.Info("Subtracting operation applied successfully", "name", m.Name, "labels", m.Labels, "value", m.Value)
+ rpc.log.Info("subtracting operation finished successfully", "name", m.Name, "labels", m.Labels, "value", m.Value)
*ok = true
return nil
@@ -116,7 +116,7 @@ func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
// Observe the value (histogram and summary only).
func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
const op = errors.Op("metrics_plugin_observe")
- rpc.log.Info("Observing metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
+ rpc.log.Info("observing metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
@@ -171,7 +171,7 @@ func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
// error
func (rpc *rpcServer) Declare(nc *NamedCollector, ok *bool) error {
const op = errors.Op("metrics_plugin_declare")
- rpc.log.Info("Declaring new metric", "name", nc.Name, "type", nc.Type, "namespace", nc.Namespace)
+ rpc.log.Info("declaring new metric", "name", nc.Name, "type", nc.Type, "namespace", nc.Namespace)
_, exist := rpc.svc.collectors.Load(nc.Name)
if exist {
rpc.log.Error("metric with provided name already exist", "name", nc.Name, "type", nc.Type, "namespace", nc.Namespace)
@@ -256,7 +256,7 @@ func (rpc *rpcServer) Declare(nc *NamedCollector, ok *bool) error {
// Set the metric value (only for gaude).
func (rpc *rpcServer) Set(m *Metric, ok *bool) (err error) {
const op = errors.Op("metrics_plugin_set")
- rpc.log.Info("Observing metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
+ rpc.log.Info("observing metric", "name", m.Name, "value", m.Value, "labels", m.Labels)
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
diff --git a/plugins/rpc/plugin.go b/plugins/rpc/plugin.go
index 55b24cd1..e13768f0 100644
--- a/plugins/rpc/plugin.go
+++ b/plugins/rpc/plugin.go
@@ -86,8 +86,7 @@ func (s *Plugin) Serve() chan error {
conn, err := s.listener.Accept()
if err != nil {
if atomic.LoadUint32(s.closed) == 1 {
- // just log and continue, this is not a critical issue, we just called Stop
- s.log.Warn("listener accept error, connection closed", "error", err)
+ // just continue, this is not a critical issue, we just called Stop
return
}
diff --git a/tests/mocks/mock_log.go b/tests/mocks/mock_log.go
index e9631805..66c70b91 100644
--- a/tests/mocks/mock_log.go
+++ b/tests/mocks/mock_log.go
@@ -2,6 +2,7 @@ package mocks
import (
"reflect"
+ "sync"
"github.com/golang/mock/gomock"
"github.com/spiral/roadrunner/v2/plugins/logger"
@@ -9,6 +10,7 @@ import (
// MockLogger is a mock of Logger interface.
type MockLogger struct {
+ sync.Mutex
ctrl *gomock.Controller
recorder *MockLoggerMockRecorder
}
@@ -38,6 +40,8 @@ func (m *MockLogger) Init() error {
// Debug mocks base method.
func (m *MockLogger) Debug(msg string, keyvals ...interface{}) {
+ m.Lock()
+ defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
for _, a := range keyvals {
@@ -48,6 +52,8 @@ func (m *MockLogger) Debug(msg string, keyvals ...interface{}) {
// Warn mocks base method.
func (m *MockLogger) Warn(msg string, keyvals ...interface{}) {
+ m.Lock()
+ defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
for _, a := range keyvals {
@@ -58,6 +64,8 @@ func (m *MockLogger) Warn(msg string, keyvals ...interface{}) {
// Info mocks base method.
func (m *MockLogger) Info(msg string, keyvals ...interface{}) {
+ m.Lock()
+ defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
for _, a := range keyvals {
@@ -68,6 +76,8 @@ func (m *MockLogger) Info(msg string, keyvals ...interface{}) {
// Error mocks base method.
func (m *MockLogger) Error(msg string, keyvals ...interface{}) {
+ m.Lock()
+ defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
for _, a := range keyvals {
diff --git a/tests/plugins/checker/configs/.rr-checker-init.yaml b/tests/plugins/checker/configs/.rr-checker-init.yaml
index 5149d27c..11804a21 100755
--- a/tests/plugins/checker/configs/.rr-checker-init.yaml
+++ b/tests/plugins/checker/configs/.rr-checker-init.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6005
- disabled: false
server:
command: "php ../../http/client.php echo pipes"
diff --git a/tests/plugins/config/.rr.yaml b/tests/plugins/config/.rr.yaml
index bad2846a..a6e80921 100755
--- a/tests/plugins/config/.rr.yaml
+++ b/tests/plugins/config/.rr.yaml
@@ -2,7 +2,6 @@ rpc:
listen: tcp://localhost:6060
reload:
- enabled: true
interval: 1s
patterns: [".php"]
services:
diff --git a/tests/plugins/gzip/plugin_test.go b/tests/plugins/gzip/plugin_test.go
index 66767364..3e3db0f8 100644
--- a/tests/plugins/gzip/plugin_test.go
+++ b/tests/plugins/gzip/plugin_test.go
@@ -7,6 +7,7 @@ import (
"sync"
"syscall"
"testing"
+ "time"
"github.com/golang/mock/gomock"
endure "github.com/spiral/endure/pkg/container"
@@ -172,6 +173,7 @@ func TestMiddlewareNotExist(t *testing.T) {
}
}()
+ time.Sleep(time.Second)
stopCh <- struct{}{}
wg.Wait()
}
diff --git a/tests/plugins/headers/headers_plugin_test.go b/tests/plugins/headers/headers_plugin_test.go
index 82a99dd1..49d86b00 100644
--- a/tests/plugins/headers/headers_plugin_test.go
+++ b/tests/plugins/headers/headers_plugin_test.go
@@ -80,6 +80,7 @@ func TestHeadersInit(t *testing.T) {
}
}()
+ time.Sleep(time.Second)
stopCh <- struct{}{}
wg.Wait()
}
diff --git a/tests/plugins/http/configs/.rr-broken-pipes.yaml b/tests/plugins/http/configs/.rr-broken-pipes.yaml
index bfcbf592..9b7d2d0b 100644
--- a/tests/plugins/http/configs/.rr-broken-pipes.yaml
+++ b/tests/plugins/http/configs/.rr-broken-pipes.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php broken pipes"
diff --git a/tests/plugins/http/configs/.rr-env.yaml b/tests/plugins/http/configs/.rr-env.yaml
index 219bad19..e6b00b69 100644
--- a/tests/plugins/http/configs/.rr-env.yaml
+++ b/tests/plugins/http/configs/.rr-env.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php env pipes"
diff --git a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
index 05c3d40a..55b2857d 100644
--- a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
@@ -30,7 +30,6 @@ http:
fcgi:
address: tcp://127.0.0.1:6921
http2:
- enabled: false
h2c: false
maxConcurrentStreams: 128
logs:
diff --git a/tests/plugins/http/configs/.rr-fcgi.yaml b/tests/plugins/http/configs/.rr-fcgi.yaml
index cfd4b79b..483da057 100644
--- a/tests/plugins/http/configs/.rr-fcgi.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi.yaml
@@ -30,7 +30,6 @@ http:
fcgi:
address: tcp://0.0.0.0:6920
http2:
- enabled: false
h2c: false
maxConcurrentStreams: 128
logs:
diff --git a/tests/plugins/http/configs/.rr-h2c.yaml b/tests/plugins/http/configs/.rr-h2c.yaml
index c2703182..2061a76b 100644
--- a/tests/plugins/http/configs/.rr-h2c.yaml
+++ b/tests/plugins/http/configs/.rr-h2c.yaml
@@ -21,7 +21,6 @@ http:
allocate_timeout: 60s
destroy_timeout: 60s
http2:
- enabled: true
h2c: true
maxConcurrentStreams: 128
logs:
diff --git a/tests/plugins/http/configs/.rr-http.yaml b/tests/plugins/http/configs/.rr-http.yaml
index 30d31819..184a353c 100644
--- a/tests/plugins/http/configs/.rr-http.yaml
+++ b/tests/plugins/http/configs/.rr-http.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php echo pipes"
diff --git a/tests/plugins/http/configs/.rr-init.yaml b/tests/plugins/http/configs/.rr-init.yaml
index 01b90b44..9b7d65c3 100644
--- a/tests/plugins/http/configs/.rr-init.yaml
+++ b/tests/plugins/http/configs/.rr-init.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php echo pipes"
@@ -34,7 +33,6 @@ http:
fcgi:
address: tcp://0.0.0.0:7921
http2:
- enabled: false
h2c: false
maxConcurrentStreams: 128
logs:
diff --git a/tests/plugins/http/configs/.rr-no-http.yaml b/tests/plugins/http/configs/.rr-no-http.yaml
index 6466c950..a6747b5d 100644
--- a/tests/plugins/http/configs/.rr-no-http.yaml
+++ b/tests/plugins/http/configs/.rr-no-http.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php echo pipes"
diff --git a/tests/plugins/http/configs/.rr-resetter.yaml b/tests/plugins/http/configs/.rr-resetter.yaml
index 88c54858..a1ef27d1 100644
--- a/tests/plugins/http/configs/.rr-resetter.yaml
+++ b/tests/plugins/http/configs/.rr-resetter.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../http/client.php echo pipes"
diff --git a/tests/plugins/informer/.rr-informer.yaml b/tests/plugins/informer/.rr-informer.yaml
index e5853b21..e1edbb44 100644
--- a/tests/plugins/informer/.rr-informer.yaml
+++ b/tests/plugins/informer/.rr-informer.yaml
@@ -10,7 +10,6 @@ server:
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
logs:
mode: development
level: error \ No newline at end of file
diff --git a/tests/plugins/informer/informer_test.go b/tests/plugins/informer/informer_test.go
index 41f1e21a..31e14ff4 100644
--- a/tests/plugins/informer/informer_test.go
+++ b/tests/plugins/informer/informer_test.go
@@ -86,13 +86,14 @@ func TestInformerInit(t *testing.T) {
}()
time.Sleep(time.Second)
- t.Run("InformerRpcTest", informerRPCTest)
+ t.Run("InformerWorkersRpcTest", informerWorkersRPCTest)
+ t.Run("InformerListRpcTest", informerListRPCTest)
stopCh <- struct{}{}
wg.Wait()
}
-func informerRPCTest(t *testing.T) {
+func informerWorkersRPCTest(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
assert.NoError(t, err)
client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
@@ -106,3 +107,15 @@ func informerRPCTest(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, list.Workers, 10)
}
+
+func informerListRPCTest(t *testing.T) {
+ conn, err := net.Dial("tcp", "127.0.0.1:6001")
+ assert.NoError(t, err)
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
+ // WorkerList contains list of workers.
+ list := make([]string, 0, 0)
+
+ err = client.Call("informer.List", true, &list)
+ assert.NoError(t, err)
+ assert.Equal(t, "informer.plugin1", list[0])
+}
diff --git a/tests/plugins/kv/boltdb/configs/.rr-init.yaml b/tests/plugins/kv/boltdb/configs/.rr-init.yaml
index bc404d8c..e4644511 100644
--- a/tests/plugins/kv/boltdb/configs/.rr-init.yaml
+++ b/tests/plugins/kv/boltdb/configs/.rr-init.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../../psr-worker-bench.php"
diff --git a/tests/plugins/kv/memcached/configs/.rr-init.yaml b/tests/plugins/kv/memcached/configs/.rr-init.yaml
index 34fb4a7d..fbca3250 100644
--- a/tests/plugins/kv/memcached/configs/.rr-init.yaml
+++ b/tests/plugins/kv/memcached/configs/.rr-init.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../../psr-worker-bench.php"
diff --git a/tests/plugins/kv/memory/configs/.rr-init.yaml b/tests/plugins/kv/memory/configs/.rr-init.yaml
index 7af2d65f..8780a622 100644
--- a/tests/plugins/kv/memory/configs/.rr-init.yaml
+++ b/tests/plugins/kv/memory/configs/.rr-init.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
server:
command: "php ../../../psr-worker-bench.php"
@@ -39,7 +38,5 @@ http:
# in memory KV driver
memory:
- enabled:
- true
# keys ttl check interval
interval: 1
diff --git a/tests/plugins/metrics/.rr-test.yaml b/tests/plugins/metrics/.rr-test.yaml
index 37c50395..bc68b90f 100644
--- a/tests/plugins/metrics/.rr-test.yaml
+++ b/tests/plugins/metrics/.rr-test.yaml
@@ -1,6 +1,5 @@
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
metrics:
# prometheus client address (path /metrics added automatically)
diff --git a/tests/plugins/metrics/metrics_test.go b/tests/plugins/metrics/metrics_test.go
index 4e81a65f..b5a4fd4f 100644
--- a/tests/plugins/metrics/metrics_test.go
+++ b/tests/plugins/metrics/metrics_test.go
@@ -11,12 +11,14 @@ import (
"testing"
"time"
+ "github.com/golang/mock/gomock"
endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/spiral/roadrunner/v2/plugins/metrics"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
+ "github.com/spiral/roadrunner/v2/tests/mocks"
"github.com/stretchr/testify/assert"
)
@@ -75,6 +77,7 @@ func TestMetricsInit(t *testing.T) {
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
tt := time.NewTimer(time.Second * 5)
+ defer tt.Stop()
out, err := get()
assert.NoError(t, err)
@@ -138,6 +141,7 @@ func TestMetricsGaugeCollector(t *testing.T) {
time.Sleep(time.Second)
tt := time.NewTimer(time.Second * 5)
+ defer tt.Stop()
out, err := get()
assert.NoError(t, err)
@@ -183,11 +187,77 @@ func TestMetricsDifferentRPCCalls(t *testing.T) {
cfg.Prefix = "rr"
cfg.Path = ".rr-test.yaml"
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Debug("Started RPC service", "address", "tcp://127.0.0.1:6001", "services", []string{"metrics"}).MinTimes(1)
+
+ mockLogger.EXPECT().Info("adding metric", "name", "counter_CounterMetric", "value", gomock.Any(), "labels", []string{"type2", "section2"}).MinTimes(1)
+ mockLogger.EXPECT().Info("adding metric", "name", "histogram_registerHistogram", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("adding metric", "name", "sub_gauge_subVector", "value", gomock.Any(), "labels", []string{"core", "first"}).MinTimes(1)
+ mockLogger.EXPECT().Info("adding metric", "name", "sub_gauge_subMetric", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("adding metric", "name", "test_metrics_named_collector", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("metric successfully added", "name", "observe_observeMetricNotEnoughLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "observe_observeMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "counter_CounterMetric", "labels", []string{"type2", "section2"}, "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "counter_CounterMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "histogram_registerHistogram", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "sub_gauge_subVector", "labels", []string{"core", "first"}, "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "sub_gauge_subVector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "sub_gauge_subMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "sub_gauge_subMetric", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "histogram_setOnHistogram", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "gauge_setWithoutLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "gauge_missing_section_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "gauge_2_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "test_metrics_named_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "test_metrics_named_collector", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("metric successfully added", "name", "user_gauge_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("declaring new metric", "name", "observe_observeMetricNotEnoughLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "observe_observeMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "counter_CounterMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "histogram_registerHistogram", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "sub_gauge_subVector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "sub_gauge_subMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "histogram_setOnHistogram", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "gauge_setWithoutLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "gauge_missing_section_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "test_metrics_named_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "gauge_2_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("declaring new metric", "name", "user_gauge_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("observing metric", "name", "observe_observeMetric", "value", gomock.Any(), "labels", []string{"test"}).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "observe_observeMetric", "value", gomock.Any(), "labels", []string{"test", "test2"}).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "gauge_setOnHistogram", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "gauge_setWithoutLabels", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "gauge_missing_section_collector", "value", gomock.Any(), "labels", []string{"missing"}).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "user_gauge_collector", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("observing metric", "name", "gauge_2_collector", "value", gomock.Any(), "labels", []string{"core", "first"}).MinTimes(1)
+
+ mockLogger.EXPECT().Info("observe operation finished successfully", "name", "observe_observeMetric", "labels", []string{"test", "test2"}, "value", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("set operation finished successfully", "name", "gauge_2_collector", "labels", []string{"core", "first"}, "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("set operation finished successfully", "name", "user_gauge_collector", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("subtracting value from metric", "name", "sub_gauge_subVector", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("subtracting value from metric", "name", "sub_gauge_subMetric", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Info("subtracting operation finished successfully", "name", "sub_gauge_subVector", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("subtracting operation finished successfully", "name", "sub_gauge_subMetric", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1)
+
+ mockLogger.EXPECT().Error("failed to get metrics with label values", "collector", "gauge_missing_section_collector", "labels", []string{"missing"}).MinTimes(1)
+ mockLogger.EXPECT().Error("required labels for collector", "collector", "gauge_setWithoutLabels").MinTimes(1)
+ mockLogger.EXPECT().Error("failed to get metrics with label values", "collector", "observe_observeMetric", "labels", []string{"test"}).MinTimes(1)
+
err = cont.RegisterAll(
cfg,
&metrics.Plugin{},
&rpcPlugin.Plugin{},
- &logger.ZapLogger{},
+ mockLogger,
)
assert.NoError(t, err)
@@ -202,8 +272,10 @@ func TestMetricsDifferentRPCCalls(t *testing.T) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+ tt := time.NewTimer(time.Minute * 3)
+ defer tt.Stop()
+
go func() {
- tt := time.NewTimer(time.Minute * 3)
for {
select {
case e := <-ch:
diff --git a/tests/plugins/mocks/mock_log.go b/tests/plugins/mocks/mock_log.go
deleted file mode 100644
index e9631805..00000000
--- a/tests/plugins/mocks/mock_log.go
+++ /dev/null
@@ -1,150 +0,0 @@
-package mocks
-
-import (
- "reflect"
-
- "github.com/golang/mock/gomock"
- "github.com/spiral/roadrunner/v2/plugins/logger"
-)
-
-// MockLogger is a mock of Logger interface.
-type MockLogger struct {
- ctrl *gomock.Controller
- recorder *MockLoggerMockRecorder
-}
-
-// MockLoggerMockRecorder is the mock recorder for MockLogger.
-type MockLoggerMockRecorder struct {
- mock *MockLogger
-}
-
-// NewMockLogger creates a new mock instance.
-func NewMockLogger(ctrl *gomock.Controller) *MockLogger {
- mock := &MockLogger{ctrl: ctrl}
- mock.recorder = &MockLoggerMockRecorder{mock}
- return mock
-}
-
-// EXPECT returns an object that allows the caller to indicate expected use.
-func (m *MockLogger) EXPECT() *MockLoggerMockRecorder {
- return m.recorder
-}
-
-func (m *MockLogger) Init() error {
- mock := &MockLogger{ctrl: m.ctrl}
- mock.recorder = &MockLoggerMockRecorder{mock}
- return nil
-}
-
-// Debug mocks base method.
-func (m *MockLogger) Debug(msg string, keyvals ...interface{}) {
- m.ctrl.T.Helper()
- varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
- m.ctrl.Call(m, "Debug", varargs...)
-}
-
-// Warn mocks base method.
-func (m *MockLogger) Warn(msg string, keyvals ...interface{}) {
- m.ctrl.T.Helper()
- varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
- m.ctrl.Call(m, "Warn", varargs...)
-}
-
-// Info mocks base method.
-func (m *MockLogger) Info(msg string, keyvals ...interface{}) {
- m.ctrl.T.Helper()
- varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
- m.ctrl.Call(m, "Info", varargs...)
-}
-
-// Error mocks base method.
-func (m *MockLogger) Error(msg string, keyvals ...interface{}) {
- m.ctrl.T.Helper()
- varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
- m.ctrl.Call(m, "Error", varargs...)
-}
-
-// Warn indicates an expected call of Warn.
-func (mr *MockLoggerMockRecorder) Warn(msg interface{}, keyvals ...interface{}) *gomock.Call {
- mr.mock.ctrl.T.Helper()
- varargs := append([]interface{}{msg}, keyvals...)
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warn", reflect.TypeOf((*MockLogger)(nil).Warn), varargs...)
-}
-
-// Debug indicates an expected call of Debug.
-func (mr *MockLoggerMockRecorder) Debug(msg interface{}, keyvals ...interface{}) *gomock.Call {
- mr.mock.ctrl.T.Helper()
- varargs := append([]interface{}{msg}, keyvals...)
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockLogger)(nil).Debug), varargs...)
-}
-
-// Error indicates an expected call of Error.
-func (mr *MockLoggerMockRecorder) Error(msg interface{}, keyvals ...interface{}) *gomock.Call {
- mr.mock.ctrl.T.Helper()
- varargs := append([]interface{}{msg}, keyvals...)
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockLogger)(nil).Error), varargs...)
-}
-
-func (mr *MockLoggerMockRecorder) Init() error {
- return nil
-}
-
-// Info indicates an expected call of Info.
-func (mr *MockLoggerMockRecorder) Info(msg interface{}, keyvals ...interface{}) *gomock.Call {
- mr.mock.ctrl.T.Helper()
- varargs := append([]interface{}{msg}, keyvals...)
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockLogger)(nil).Info), varargs...)
-}
-
-// MockWithLogger is a mock of WithLogger interface.
-type MockWithLogger struct {
- ctrl *gomock.Controller
- recorder *MockWithLoggerMockRecorder
-}
-
-// MockWithLoggerMockRecorder is the mock recorder for MockWithLogger.
-type MockWithLoggerMockRecorder struct {
- mock *MockWithLogger
-}
-
-// NewMockWithLogger creates a new mock instance.
-func NewMockWithLogger(ctrl *gomock.Controller) *MockWithLogger {
- mock := &MockWithLogger{ctrl: ctrl}
- mock.recorder = &MockWithLoggerMockRecorder{mock}
- return mock
-}
-
-// EXPECT returns an object that allows the caller to indicate expected use.
-func (m *MockWithLogger) EXPECT() *MockWithLoggerMockRecorder {
- return m.recorder
-}
-
-// With mocks base method.
-func (m *MockWithLogger) With(keyvals ...interface{}) logger.Logger {
- m.ctrl.T.Helper()
- varargs := []interface{}{}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
- ret := m.ctrl.Call(m, "With", varargs...)
- ret0, _ := ret[0].(logger.Logger)
- return ret0
-}
-
-// With indicates an expected call of With.
-func (mr *MockWithLoggerMockRecorder) With(keyvals ...interface{}) *gomock.Call {
- mr.mock.ctrl.T.Helper()
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "With", reflect.TypeOf((*MockWithLogger)(nil).With), keyvals...)
-}
diff --git a/tests/plugins/resetter/.rr-resetter.yaml b/tests/plugins/resetter/.rr-resetter.yaml
index e5853b21..623ba142 100644
--- a/tests/plugins/resetter/.rr-resetter.yaml
+++ b/tests/plugins/resetter/.rr-resetter.yaml
@@ -10,7 +10,6 @@ server:
rpc:
listen: tcp://127.0.0.1:6001
- disabled: false
logs:
mode: development
- level: error \ No newline at end of file
+ level: debug \ No newline at end of file
diff --git a/tests/plugins/resetter/resetter_test.go b/tests/plugins/resetter/resetter_test.go
index 6e206c7d..465d22dd 100644
--- a/tests/plugins/resetter/resetter_test.go
+++ b/tests/plugins/resetter/resetter_test.go
@@ -10,13 +10,14 @@ import (
"testing"
"time"
+ "github.com/golang/mock/gomock"
endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/config"
- "github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/spiral/roadrunner/v2/plugins/resetter"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
+ "github.com/spiral/roadrunner/v2/tests/mocks"
"github.com/stretchr/testify/assert"
)
@@ -31,10 +32,26 @@ func TestResetterInit(t *testing.T) {
Prefix: "rr",
}
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Debug("Started RPC service", "address", "tcp://127.0.0.1:6001", "services", []string{"resetter"}).MinTimes(1)
+
+ mockLogger.EXPECT().Error(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+
+ mockLogger.EXPECT().Debug("started List method").MinTimes(1)
+ mockLogger.EXPECT().Debug("services list", "services", []string{"resetter.plugin1"}).MinTimes(1)
+ mockLogger.EXPECT().Debug("finished List method").MinTimes(1)
+ mockLogger.EXPECT().Debug("started Reset method for the service", "service", "resetter.plugin1").MinTimes(1)
+ mockLogger.EXPECT().Debug("finished Reset method for the service", "service", "resetter.plugin1").MinTimes(1)
+ mockLogger.EXPECT().Warn("listener accept error, connection closed", "error", gomock.Any()).AnyTimes()
+
err = cont.RegisterAll(
cfg,
&server.Plugin{},
- &logger.ZapLogger{},
+ mockLogger,
&resetter.Plugin{},
&rpcPlugin.Plugin{},
&Plugin1{},