summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-20 18:28:46 +0300
committerValery Piashchynski <[email protected]>2020-12-20 18:28:46 +0300
commitf4a36c7f684216fb408693a6c494486144df57cf (patch)
treee1b61bf7e74cb63aa45f9ca0284a4cffe8e06b0e /plugins
parentfbd5adde5abae6f7adb7fcdafc226bcd3480d498 (diff)
parenta10d20d20e910ed8fcfbc3bc690aaf17ee338ff3 (diff)
Merge remote-tracking branch 'origin/2.0' into plugin/redis
# Conflicts: # go.sum # pkg/pipe/pipe_factory_test.go # pkg/pool/static_pool.go # plugins/rpc/plugin.go
Diffstat (limited to 'plugins')
-rw-r--r--plugins/checker/tests/plugin_test.go4
-rw-r--r--plugins/http/request.go10
-rw-r--r--plugins/http/response.go4
-rw-r--r--plugins/http/tests/http_test.go6
-rw-r--r--plugins/http/tests/response_test.go16
-rw-r--r--plugins/informer/tests/informer_test.go4
-rw-r--r--plugins/metrics/tests/metrics_test.go28
-rw-r--r--plugins/reload/tests/reload_plugin_test.go249
-rw-r--r--plugins/resetter/tests/resetter_test.go4
-rwxr-xr-xplugins/rpc/plugin.go10
-rw-r--r--plugins/rpc/tests/plugin2.go4
-rw-r--r--plugins/server/tests/plugin_pipes.go4
-rw-r--r--plugins/server/tests/plugin_sockets.go4
-rw-r--r--plugins/server/tests/plugin_tcp.go4
14 files changed, 170 insertions, 181 deletions
diff --git a/plugins/checker/tests/plugin_test.go b/plugins/checker/tests/plugin_test.go
index 02a7f953..38b751ff 100644
--- a/plugins/checker/tests/plugin_test.go
+++ b/plugins/checker/tests/plugin_test.go
@@ -13,7 +13,7 @@ import (
"time"
"github.com/spiral/endure"
- "github.com/spiral/goridge/v3"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/interfaces/status"
"github.com/spiral/roadrunner/v2/plugins/checker"
"github.com/spiral/roadrunner/v2/plugins/config"
@@ -178,7 +178,7 @@ func TestStatusRPC(t *testing.T) {
func checkRPCStatus(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6005")
assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
st := &status.Status{}
diff --git a/plugins/http/request.go b/plugins/http/request.go
index 5df79b7d..d613bcf6 100644
--- a/plugins/http/request.go
+++ b/plugins/http/request.go
@@ -10,7 +10,7 @@ import (
j "github.com/json-iterator/go"
"github.com/spiral/roadrunner/v2/interfaces/log"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
"github.com/spiral/roadrunner/v2/plugins/http/attributes"
)
@@ -136,17 +136,17 @@ func (r *Request) Close(log log.Logger) {
// Payload request marshaled RoadRunner payload based on PSR7 data. values encode method is JSON. Make sure to open
// files prior to calling this method.
-func (r *Request) Payload() (internal.Payload, error) {
- p := internal.Payload{}
+func (r *Request) Payload() (payload.Payload, error) {
+ p := payload.Payload{}
var err error
if p.Context, err = json.Marshal(r); err != nil {
- return internal.Payload{}, err
+ return payload.Payload{}, err
}
if r.Parsed {
if p.Body, err = json.Marshal(r.body); err != nil {
- return internal.Payload{}, err
+ return payload.Payload{}, err
}
} else if r.body != nil {
p.Body = r.body.([]byte)
diff --git a/plugins/http/response.go b/plugins/http/response.go
index 9700a16c..17049ce1 100644
--- a/plugins/http/response.go
+++ b/plugins/http/response.go
@@ -6,7 +6,7 @@ import (
"strings"
"sync"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
)
// Response handles PSR7 response logic.
@@ -23,7 +23,7 @@ type Response struct {
}
// NewResponse creates new response based on given pool payload.
-func NewResponse(p internal.Payload) (*Response, error) {
+func NewResponse(p payload.Payload) (*Response, error) {
r := &Response{Body: p.Body}
if err := json.Unmarshal(p.Context, r); err != nil {
return nil, err
diff --git a/plugins/http/tests/http_test.go b/plugins/http/tests/http_test.go
index 1a61597c..d7818981 100644
--- a/plugins/http/tests/http_test.go
+++ b/plugins/http/tests/http_test.go
@@ -17,7 +17,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/spiral/endure"
- "github.com/spiral/goridge/v3"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2"
"github.com/spiral/roadrunner/v2/interfaces/events"
"github.com/spiral/roadrunner/v2/mocks"
@@ -193,7 +193,7 @@ func echoHTTP(t *testing.T) {
func resetTest(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
// WorkerList contains list of workers.
var ret bool
@@ -213,7 +213,7 @@ func resetTest(t *testing.T) {
func informerTest(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
// WorkerList contains list of workers.
list := struct {
// Workers is list of workers.
diff --git a/plugins/http/tests/response_test.go b/plugins/http/tests/response_test.go
index a526fe03..7901a0d1 100644
--- a/plugins/http/tests/response_test.go
+++ b/plugins/http/tests/response_test.go
@@ -6,7 +6,7 @@ import (
"net/http"
"testing"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
http2 "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/stretchr/testify/assert"
)
@@ -45,13 +45,13 @@ func (tw *testWriter) Push(target string, opts *http.PushOptions) error {
}
func TestNewResponse_Error(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{Context: []byte(`invalid payload`)})
+ r, err := http2.NewResponse(payload.Payload{Context: []byte(`invalid payload`)})
assert.Error(t, err)
assert.Nil(t, r)
}
func TestNewResponse_Write(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
Body: []byte(`sample body`),
})
@@ -68,7 +68,7 @@ func TestNewResponse_Write(t *testing.T) {
}
func TestNewResponse_Stream(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
@@ -92,7 +92,7 @@ func TestNewResponse_Stream(t *testing.T) {
}
func TestNewResponse_StreamError(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
@@ -112,7 +112,7 @@ func TestNewResponse_StreamError(t *testing.T) {
}
func TestWrite_HandlesPush(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"Http2-Push":["/test.js"],"content-type":["text/html"]},"status": 200}`),
})
@@ -127,7 +127,7 @@ func TestWrite_HandlesPush(t *testing.T) {
}
func TestWrite_HandlesTrailers(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(`{"headers":{"Trailer":["foo, bar", "baz"],"foo":["test"],"bar":["demo"]},"status": 200}`),
})
@@ -146,7 +146,7 @@ func TestWrite_HandlesTrailers(t *testing.T) {
}
func TestWrite_HandlesHandlesWhitespacesInTrailer(t *testing.T) {
- r, err := http2.NewResponse(internal.Payload{
+ r, err := http2.NewResponse(payload.Payload{
Context: []byte(
`{"headers":{"Trailer":["foo\t,bar , baz"],"foo":["a"],"bar":["b"],"baz":["c"]},"status": 200}`),
})
diff --git a/plugins/informer/tests/informer_test.go b/plugins/informer/tests/informer_test.go
index 193e84bb..dd06f1c4 100644
--- a/plugins/informer/tests/informer_test.go
+++ b/plugins/informer/tests/informer_test.go
@@ -10,7 +10,7 @@ import (
"time"
"github.com/spiral/endure"
- "github.com/spiral/goridge/v3"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/informer"
@@ -84,7 +84,7 @@ func TestInformerInit(t *testing.T) {
func informerRPCTest(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
// WorkerList contains list of workers.
list := struct {
// Workers is list of workers.
diff --git a/plugins/metrics/tests/metrics_test.go b/plugins/metrics/tests/metrics_test.go
index 2d3a3c27..4572bc3f 100644
--- a/plugins/metrics/tests/metrics_test.go
+++ b/plugins/metrics/tests/metrics_test.go
@@ -12,7 +12,7 @@ import (
"time"
"github.com/spiral/endure"
- "github.com/spiral/goridge/v3"
+ 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"
@@ -298,7 +298,7 @@ func observeMetricNotEnoughLabels(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -331,7 +331,7 @@ func observeMetric(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -364,7 +364,7 @@ func counterMetric(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -398,7 +398,7 @@ func registerHistogram(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -434,7 +434,7 @@ func subVector(t *testing.T) {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -480,7 +480,7 @@ func subMetric(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -523,7 +523,7 @@ func setOnHistogram(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -558,7 +558,7 @@ func setWithoutLabels(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -593,7 +593,7 @@ func missingSection(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -629,7 +629,7 @@ func vectorMetric(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -665,7 +665,7 @@ func setMetric(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
@@ -698,7 +698,7 @@ func addMetricsTest(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
m := metrics.Metric{
@@ -718,7 +718,7 @@ func declareMetricsTest(t *testing.T) {
defer func() {
_ = conn.Close()
}()
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret bool
nc := metrics.NamedCollector{
diff --git a/plugins/reload/tests/reload_plugin_test.go b/plugins/reload/tests/reload_plugin_test.go
index d2fad28d..2ba9e256 100644
--- a/plugins/reload/tests/reload_plugin_test.go
+++ b/plugins/reload/tests/reload_plugin_test.go
@@ -4,7 +4,6 @@ import (
"io"
"io/ioutil"
"math/rand"
- "net/http"
"os"
"os/signal"
"path/filepath"
@@ -14,11 +13,12 @@ import (
"testing"
"time"
+ "github.com/golang/mock/gomock"
"github.com/spiral/endure"
"github.com/spiral/errors"
+ "github.com/spiral/roadrunner/v2/mocks"
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
- "github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/spiral/roadrunner/v2/plugins/reload"
"github.com/spiral/roadrunner/v2/plugins/resetter"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -27,7 +27,8 @@ import (
const testDir string = "unit_tests"
const testCopyToDir string = "unit_tests_copied"
-const hugeNumberOfFiles uint = 5000
+const dir1 string = "dir1"
+const hugeNumberOfFiles uint = 500
func TestReloadInit(t *testing.T) {
cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
@@ -43,13 +44,20 @@ func TestReloadInit(t *testing.T) {
err = os.Mkdir(testDir, 0755)
assert.NoError(t, err)
- defer func() {
- assert.NoError(t, freeResources(testDir))
- }()
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("http handler response received", "elapsed", gomock.Any(), "remote address", "127.0.0.1").Times(1)
+ mockLogger.EXPECT().Debug("file was created", "path", gomock.Any(), "name", "file.txt", "size", gomock.Any()).Times(2)
+ mockLogger.EXPECT().Debug("file was added to watcher", "path", gomock.Any(), "name", "file.txt", "size", gomock.Any()).Times(2)
+ mockLogger.EXPECT().Info("HTTP plugin got restart request. Restarting...").Times(1)
+ mockLogger.EXPECT().Info("HTTP workers Pool successfully restarted").Times(1)
+ mockLogger.EXPECT().Info("HTTP listeners successfully re-added").Times(1)
+ mockLogger.EXPECT().Info("HTTP plugin successfully restarted").Times(1)
err = cont.RegisterAll(
cfg,
- &logger.ZapLogger{},
+ mockLogger,
&server.Plugin{},
&httpPlugin.Plugin{},
&reload.Plugin{},
@@ -58,9 +66,7 @@ func TestReloadInit(t *testing.T) {
assert.NoError(t, err)
err = cont.Init()
- if err != nil {
- t.Fatal(err)
- }
+ assert.NoError(t, err)
ch, err := cont.Serve()
assert.NoError(t, err)
@@ -101,9 +107,9 @@ func TestReloadInit(t *testing.T) {
}()
t.Run("ReloadTestInit", reloadTestInit)
- reloadHTTPLiveAfterReset(t, "22388")
wg.Wait()
+ assert.NoError(t, freeResources(testDir))
}
func reloadTestInit(t *testing.T) {
@@ -124,19 +130,26 @@ func TestReloadHugeNumberOfFiles(t *testing.T) {
// try to remove, skip error
assert.NoError(t, freeResources(testDir))
assert.NoError(t, freeResources(testCopyToDir))
- err = os.Mkdir(testDir, 0755)
- assert.NoError(t, err)
- err = os.Mkdir(testCopyToDir, 0755)
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, freeResources(testDir))
- assert.NoError(t, freeResources(testCopyToDir))
- }()
+ assert.NoError(t, os.Mkdir(testDir, 0755))
+ assert.NoError(t, os.Mkdir(testCopyToDir, 0755))
+
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("file added to the list of removed files", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Debug("http handler response received", "elapsed", gomock.Any(), "remote address", "127.0.0.1").Times(1)
+ mockLogger.EXPECT().Debug("file was created", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Debug("file was updated", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Debug("file was added to watcher", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP plugin got restart request. Restarting...").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP workers Pool successfully restarted").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP listeners successfully re-added").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP plugin successfully restarted").MinTimes(1)
err = cont.RegisterAll(
cfg,
- &logger.ZapLogger{},
+ mockLogger,
&server.Plugin{},
&httpPlugin.Plugin{},
&reload.Plugin{},
@@ -145,9 +158,7 @@ func TestReloadHugeNumberOfFiles(t *testing.T) {
assert.NoError(t, err)
err = cont.Init()
- if err != nil {
- t.Fatal(err)
- }
+ assert.NoError(t, err)
ch, err := cont.Serve()
assert.NoError(t, err)
@@ -158,7 +169,7 @@ func TestReloadHugeNumberOfFiles(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
- tt := time.NewTimer(time.Second * 100)
+ tt := time.NewTimer(time.Second * 60)
go func() {
defer wg.Done()
@@ -188,22 +199,20 @@ func TestReloadHugeNumberOfFiles(t *testing.T) {
}()
t.Run("ReloadTestHugeNumberOfFiles", reloadHugeNumberOfFiles)
- ttt := time.Now()
t.Run("ReloadRandomlyChangeFile", randomlyChangeFile)
- if time.Since(ttt).Seconds() > 80 {
- t.Fatal("spend too much time on reloading")
- }
- reloadHTTPLiveAfterReset(t, "22388")
wg.Wait()
+
+ assert.NoError(t, freeResources(testDir))
+ assert.NoError(t, freeResources(testCopyToDir))
}
func randomlyChangeFile(t *testing.T) {
- // we know, that directory contains 5000 files (0-4999)
+ // we know, that directory contains 500 files (0-499)
// let's try to randomly change it
- for i := 0; i < 100; i++ {
+ for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(500) // nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
rNum := rand.Int63n(int64(hugeNumberOfFiles)) // nolint:gosec
err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".txt"), []byte("Hello, Gophers!"), 0755) // nolint:gosec
@@ -229,16 +238,23 @@ func TestReloadFilterFileExt(t *testing.T) {
// try to remove, skip error
assert.NoError(t, freeResources(testDir))
- err = os.Mkdir(testDir, 0755)
- assert.NoError(t, err)
+ assert.NoError(t, os.Mkdir(testDir, 0755))
- defer func() {
- assert.NoError(t, freeResources(testDir))
- }()
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("http handler response received", "elapsed", gomock.Any(), "remote address", "127.0.0.1").Times(1)
+ mockLogger.EXPECT().Debug("file was created", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(100)
+ mockLogger.EXPECT().Debug("file was added to watcher", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Debug("file added to the list of removed files", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).AnyTimes()
+ mockLogger.EXPECT().Info("HTTP plugin got restart request. Restarting...").Times(1)
+ mockLogger.EXPECT().Info("HTTP workers Pool successfully restarted").Times(1)
+ mockLogger.EXPECT().Info("HTTP listeners successfully re-added").Times(1)
+ mockLogger.EXPECT().Info("HTTP plugin successfully restarted").Times(1)
err = cont.RegisterAll(
cfg,
- &logger.ZapLogger{},
+ mockLogger,
&server.Plugin{},
&httpPlugin.Plugin{},
&reload.Plugin{},
@@ -247,9 +263,7 @@ func TestReloadFilterFileExt(t *testing.T) {
assert.NoError(t, err)
err = cont.Init()
- if err != nil {
- t.Fatal(err)
- }
+ assert.NoError(t, err)
ch, err := cont.Serve()
assert.NoError(t, err)
@@ -260,7 +274,7 @@ func TestReloadFilterFileExt(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
- tt := time.NewTimer(time.Second * 40)
+ tt := time.NewTimer(time.Second * 60)
go func() {
defer wg.Done()
@@ -290,15 +304,11 @@ func TestReloadFilterFileExt(t *testing.T) {
}()
t.Run("ReloadMakeFiles", reloadMakeFiles)
- ttt := time.Now()
t.Run("ReloadFilteredExt", reloadFilteredExt)
- if time.Since(ttt).Seconds() > 20 {
- t.Fatal("spend too much time on reloading")
- }
-
- reloadHTTPLiveAfterReset(t, "27388")
wg.Wait()
+
+ assert.NoError(t, freeResources(testDir))
}
func reloadMakeFiles(t *testing.T) {
@@ -336,7 +346,7 @@ func reloadFilteredExt(t *testing.T) {
}
// Should be events only about creating files with txt ext
-func TestReloadCopy3k(t *testing.T) {
+func TestReloadCopy500(t *testing.T) {
cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
assert.NoError(t, err)
@@ -348,23 +358,29 @@ func TestReloadCopy3k(t *testing.T) {
// try to remove, skip error
assert.NoError(t, freeResources(testDir))
assert.NoError(t, freeResources(testCopyToDir))
- assert.NoError(t, freeResources("dir1"))
- err = os.Mkdir(testDir, 0755)
- assert.NoError(t, err)
- err = os.Mkdir(testCopyToDir, 0755)
- assert.NoError(t, err)
- err = os.Mkdir("dir1", 0755)
- assert.NoError(t, err)
-
- defer func() {
- assert.NoError(t, freeResources(testDir))
- assert.NoError(t, freeResources(testCopyToDir))
- assert.NoError(t, freeResources("dir1"))
- }()
+ assert.NoError(t, freeResources(dir1))
+
+ assert.NoError(t, os.Mkdir(testDir, 0755))
+ assert.NoError(t, os.Mkdir(testCopyToDir, 0755))
+ assert.NoError(t, os.Mkdir(dir1, 0755))
+
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+ //
+ mockLogger.EXPECT().Debug("http handler response received", "elapsed", gomock.Any(), "remote address", "127.0.0.1").Times(1)
+ mockLogger.EXPECT().Debug("file was created", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(50)
+ mockLogger.EXPECT().Debug("file was added to watcher", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(50)
+ mockLogger.EXPECT().Debug("file added to the list of removed files", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(50)
+ mockLogger.EXPECT().Debug("file was removed from watcher", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(50)
+ mockLogger.EXPECT().Debug("file was updated", "path", gomock.Any(), "name", gomock.Any(), "size", gomock.Any()).MinTimes(50)
+ mockLogger.EXPECT().Info("HTTP plugin got restart request. Restarting...").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP workers Pool successfully restarted").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP listeners successfully re-added").MinTimes(1)
+ mockLogger.EXPECT().Info("HTTP plugin successfully restarted").MinTimes(1)
err = cont.RegisterAll(
cfg,
- &logger.ZapLogger{},
+ mockLogger,
&server.Plugin{},
&httpPlugin.Plugin{},
&reload.Plugin{},
@@ -373,9 +389,7 @@ func TestReloadCopy3k(t *testing.T) {
assert.NoError(t, err)
err = cont.Init()
- if err != nil {
- t.Fatal(err)
- }
+ assert.NoError(t, err)
ch, err := cont.Serve()
assert.NoError(t, err)
@@ -386,7 +400,7 @@ func TestReloadCopy3k(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
- tt := time.NewTimer(time.Second * 220)
+ tt := time.NewTimer(time.Second * 120)
go func() {
defer wg.Done()
@@ -398,6 +412,7 @@ func TestReloadCopy3k(t *testing.T) {
if err != nil {
assert.FailNow(t, "error", err.Error())
}
+ return
case <-sig:
err = cont.Stop()
if err != nil {
@@ -426,19 +441,16 @@ func TestReloadCopy3k(t *testing.T) {
// 3
// Recursive
- t.Run("ReloadMake3kFiles", reloadMake3kFiles)
- ttt := time.Now()
+ t.Run("ReloadMake300Files", reloadMake300Files)
t.Run("ReloadCopyFiles", reloadCopyFiles)
- if time.Since(ttt).Seconds() > 120 {
- t.Fatal("spend too much time on copy")
- }
-
t.Run("ReloadRecursiveDirsSupport", copyFilesRecursive)
t.Run("RandomChangesInRecursiveDirs", randomChangesInRecursiveDirs)
t.Run("RemoveFilesSupport", removeFilesSupport)
t.Run("ReloadMoveSupport", reloadMoveSupport)
- reloadHTTPLiveAfterReset(t, "37388")
+ assert.NoError(t, freeResources(testDir))
+ assert.NoError(t, freeResources(testCopyToDir))
+ assert.NoError(t, freeResources(dir1))
wg.Wait()
}
@@ -446,11 +458,11 @@ func TestReloadCopy3k(t *testing.T) {
func reloadMoveSupport(t *testing.T) {
t.Run("MoveSupportCopy", copyFilesRecursive)
// move some files
- for i := 0; i < 50; i++ {
+ for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(500) // nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(200)) // nolint:gosec
+ rNum := rand.Int63n(int64(100)) // nolint:gosec
rDir := rand.Int63n(9) // nolint:gosec
rExt := rand.Int63n(3) // nolint:gosec
@@ -482,11 +494,11 @@ func reloadMoveSupport(t *testing.T) {
func removeFilesSupport(t *testing.T) {
// remove some files
- for i := 0; i < 50; i++ {
+ for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(500) // nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(200)) // nolint:gosec
+ rNum := rand.Int63n(int64(100)) // nolint:gosec
rDir := rand.Int63n(10) // nolint:gosec
rExt := rand.Int63n(3) // nolint:gosec
@@ -509,8 +521,8 @@ func removeFilesSupport(t *testing.T) {
"dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9",
"dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10",
}
- err := os.Remove(filepath.Join(dirs[rDir], "file_"+strconv.Itoa(int(rNum))+ext[rExt]))
- assert.NoError(t, err)
+ // here can be a situation, when file already deleted
+ _ = os.Remove(filepath.Join(dirs[rDir], "file_"+strconv.Itoa(int(rNum))+ext[rExt]))
}
}
@@ -540,11 +552,11 @@ func randomChangesInRecursiveDirs(t *testing.T) {
"foo_", // should be created
"bar_", // should be created
}
- for i := 0; i < 50; i++ {
+ for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(500) // nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(200)) // nolint:gosec
+ rNum := rand.Int63n(int64(100)) // nolint:gosec
rDir := rand.Int63n(10) // nolint:gosec
rExt := rand.Int63n(3) // nolint:gosec
rName := rand.Int63n(3) // nolint:gosec
@@ -583,19 +595,18 @@ func reloadCopyFiles(t *testing.T) {
assert.NoError(t, freeResources(testDir))
assert.NoError(t, freeResources(testCopyToDir))
- err = os.Mkdir(testDir, 0755)
- assert.NoError(t, err)
- err = os.Mkdir(testCopyToDir, 0755)
- assert.NoError(t, err)
+
+ assert.NoError(t, os.Mkdir(testDir, 0755))
+ assert.NoError(t, os.Mkdir(testCopyToDir, 0755))
// recreate files
- for i := uint(0); i < 200; i++ {
+ for i := uint(0); i < 100; i++ {
assert.NoError(t, makeFile("file_"+strconv.Itoa(int(i))+".txt"))
}
- for i := uint(0); i < 200; i++ {
+ for i := uint(0); i < 100; i++ {
assert.NoError(t, makeFile("file_"+strconv.Itoa(int(i))+".abc"))
}
- for i := uint(0); i < 200; i++ {
+ for i := uint(0); i < 100; i++ {
assert.NoError(t, makeFile("file_"+strconv.Itoa(int(i))+".def"))
}
@@ -603,7 +614,7 @@ func reloadCopyFiles(t *testing.T) {
assert.NoError(t, err)
}
-func reloadMake3kFiles(t *testing.T) {
+func reloadMake300Files(t *testing.T) {
for i := uint(0); i < 100; i++ {
assert.NoError(t, makeFile("file_"+strconv.Itoa(int(i))+".txt"))
}
@@ -627,25 +638,21 @@ func TestReloadNoRecursion(t *testing.T) {
// try to remove, skip error
assert.NoError(t, freeResources(testDir))
assert.NoError(t, freeResources(testCopyToDir))
- assert.NoError(t, freeResources("dir1"))
- err = os.Mkdir(testDir, 0755)
- assert.NoError(t, err)
+ assert.NoError(t, freeResources(dir1))
- err = os.Mkdir("dir1", 0755)
- assert.NoError(t, err)
+ assert.NoError(t, os.Mkdir(testDir, 0755))
+ assert.NoError(t, os.Mkdir(dir1, 0755))
+ assert.NoError(t, os.Mkdir(testCopyToDir, 0755))
- err = os.Mkdir(testCopyToDir, 0755)
- assert.NoError(t, err)
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
- defer func() {
- assert.NoError(t, freeResources(testDir))
- assert.NoError(t, freeResources(testCopyToDir))
- assert.NoError(t, freeResources("dir1"))
- }()
+ // http server should not be restarted. all event from wrong file extensions should be skipped
+ mockLogger.EXPECT().Debug("http handler response received", "elapsed", gomock.Any(), "remote address", "127.0.0.1").Times(1)
err = cont.RegisterAll(
cfg,
- &logger.ZapLogger{},
+ mockLogger,
&server.Plugin{},
&httpPlugin.Plugin{},
&reload.Plugin{},
@@ -654,9 +661,7 @@ func TestReloadNoRecursion(t *testing.T) {
assert.NoError(t, err)
err = cont.Init()
- if err != nil {
- t.Fatal(err)
- }
+ assert.NoError(t, err)
ch, err := cont.Serve()
assert.NoError(t, err)
@@ -695,35 +700,19 @@ func TestReloadNoRecursion(t *testing.T) {
}
}
}()
+
t.Run("ReloadMakeFiles", reloadMakeFiles) // make files in the testDir
t.Run("ReloadCopyFilesRecursive", reloadCopyFiles)
- reloadHTTPLiveAfterReset(t, "22766")
-
wg.Wait()
+
+ assert.NoError(t, freeResources(testDir))
+ assert.NoError(t, freeResources(testCopyToDir))
+ assert.NoError(t, freeResources(dir1))
}
// ========================================================================
-func reloadHTTPLiveAfterReset(t *testing.T, port string) {
- req, err := http.NewRequest("GET", "http://localhost:"+port, nil)
- assert.NoError(t, err)
-
- r, err := http.DefaultClient.Do(req)
- if err != nil {
- t.Fatal(err)
- }
-
- b, err := ioutil.ReadAll(r.Body)
- assert.NoError(t, err)
-
- assert.Equal(t, 200, r.StatusCode)
- assert.Equal(t, "hello world", string(b))
-
- err = r.Body.Close()
- assert.NoError(t, err)
-}
-
func freeResources(path string) error {
return os.RemoveAll(path)
}
diff --git a/plugins/resetter/tests/resetter_test.go b/plugins/resetter/tests/resetter_test.go
index 45de67e3..95c3a6b4 100644
--- a/plugins/resetter/tests/resetter_test.go
+++ b/plugins/resetter/tests/resetter_test.go
@@ -10,7 +10,7 @@ import (
"time"
"github.com/spiral/endure"
- "github.com/spiral/goridge/v3"
+ 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"
@@ -83,7 +83,7 @@ func TestResetterInit(t *testing.T) {
func resetterRPCTest(t *testing.T) {
conn, err := net.Dial("tcp", "127.0.0.1:6001")
assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
// WorkerList contains list of workers.
var ret bool
diff --git a/plugins/rpc/plugin.go b/plugins/rpc/plugin.go
index 8d308561..98242ade 100755
--- a/plugins/rpc/plugin.go
+++ b/plugins/rpc/plugin.go
@@ -7,10 +7,10 @@ import (
"github.com/spiral/endure"
"github.com/spiral/errors"
- "github.com/spiral/goridge/v3"
- config2 "github.com/spiral/roadrunner/v2/interfaces/config"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/interfaces/log"
rpc_ "github.com/spiral/roadrunner/v2/interfaces/rpc"
+ "github.com/spiral/roadrunner/v2/plugins/config"
)
// PluginName contains default plugin name.
@@ -32,7 +32,7 @@ type Plugin struct {
}
// Init rpc service. Must return true if service is enabled.
-func (s *Plugin) Init(cfg config2.Configurer, log log.Logger) error {
+func (s *Plugin) Init(cfg config.Configurer, log log.Logger) error {
const op = errors.Op("RPC Init")
if !cfg.Has(PluginName) {
return errors.E(op, errors.Disabled)
@@ -100,7 +100,7 @@ func (s *Plugin) Serve() chan error {
return
}
- go s.rpc.ServeCodec(goridge.NewCodec(conn))
+ go s.rpc.ServeCodec(goridgeRpc.NewCodec(conn))
}
}()
@@ -161,5 +161,5 @@ func (s *Plugin) Client() (*rpc.Client, error) {
return nil, err
}
- return rpc.NewClientWithCodec(goridge.NewClientCodec(conn)), nil
+ return rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)), nil
}
diff --git a/plugins/rpc/tests/plugin2.go b/plugins/rpc/tests/plugin2.go
index 347e0330..411b9c54 100644
--- a/plugins/rpc/tests/plugin2.go
+++ b/plugins/rpc/tests/plugin2.go
@@ -6,7 +6,7 @@ import (
"time"
"github.com/spiral/errors"
- "github.com/spiral/goridge/v3"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
)
// plugin2 makes a call to the plugin1 via RPC
@@ -30,7 +30,7 @@ func (p2 *Plugin2) Serve() chan error {
errCh <- errors.E(errors.Serve, err)
return
}
- client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn))
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
var ret string
err = client.Call("rpc_test.plugin1.Hello", "Valery", &ret)
if err != nil {
diff --git a/plugins/server/tests/plugin_pipes.go b/plugins/server/tests/plugin_pipes.go
index f613cf98..9d7812a8 100644
--- a/plugins/server/tests/plugin_pipes.go
+++ b/plugins/server/tests/plugin_pipes.go
@@ -8,7 +8,7 @@ import (
config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/worker"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
@@ -47,7 +47,7 @@ func (f *Foo) Serve() chan error {
const op = errors.Op("serve")
// test payload for echo
- r := internal.Payload{
+ r := payload.Payload{
Context: nil,
Body: []byte(Response),
}
diff --git a/plugins/server/tests/plugin_sockets.go b/plugins/server/tests/plugin_sockets.go
index 72b4d1a8..e5b139d4 100644
--- a/plugins/server/tests/plugin_sockets.go
+++ b/plugins/server/tests/plugin_sockets.go
@@ -7,7 +7,7 @@ import (
config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
"github.com/spiral/roadrunner/v2/pkg/worker"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
)
@@ -31,7 +31,7 @@ func (f *Foo2) Serve() chan error {
conf := &plugin.Config{}
// test payload for echo
- r := internal.Payload{
+ r := payload.Payload{
Context: nil,
Body: []byte(Response),
}
diff --git a/plugins/server/tests/plugin_tcp.go b/plugins/server/tests/plugin_tcp.go
index aa741deb..866116a7 100644
--- a/plugins/server/tests/plugin_tcp.go
+++ b/plugins/server/tests/plugin_tcp.go
@@ -7,7 +7,7 @@ import (
config2 "github.com/spiral/roadrunner/v2/interfaces/config"
"github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/interfaces/server"
- "github.com/spiral/roadrunner/v2/internal"
+ "github.com/spiral/roadrunner/v2/pkg/payload"
"github.com/spiral/roadrunner/v2/pkg/worker"
plugin "github.com/spiral/roadrunner/v2/plugins/server"
)
@@ -31,7 +31,7 @@ func (f *Foo3) Serve() chan error {
conf := &plugin.Config{}
// test payload for echo
- r := internal.Payload{
+ r := payload.Payload{
Context: nil,
Body: []byte(Response),
}