summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/composer.json1
-rw-r--r--tests/mocks/mock_log.go10
-rwxr-xr-xtests/plugins/checker/configs/.rr-checker-init.yaml3
-rw-r--r--tests/plugins/checker/plugin_test.go2
-rwxr-xr-xtests/plugins/config/.rr.yaml1
-rwxr-xr-xtests/plugins/config/config_test.go2
-rw-r--r--tests/plugins/gzip/plugin_test.go4
-rw-r--r--tests/plugins/headers/headers_plugin_test.go3
-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.yaml3
-rw-r--r--tests/plugins/http/configs/.rr-fcgi.yaml3
-rw-r--r--tests/plugins/http/configs/.rr-h2c.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-http-supervised-pool.yaml33
-rw-r--r--tests/plugins/http/configs/.rr-http.yaml1
-rw-r--r--tests/plugins/http/configs/.rr-init.yaml4
-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/http/handler_test.go220
-rw-r--r--tests/plugins/http/http_plugin_test.go123
-rw-r--r--tests/plugins/http/uploads_test.go2
-rw-r--r--tests/plugins/informer/.rr-informer.yaml1
-rw-r--r--tests/plugins/informer/informer_test.go19
-rw-r--r--tests/plugins/informer/test_plugin.go26
-rw-r--r--tests/plugins/kv/boltdb/configs/.rr-init.yaml3
-rw-r--r--tests/plugins/kv/boltdb/plugin_test.go4
-rw-r--r--tests/plugins/kv/memcached/configs/.rr-init.yaml3
-rw-r--r--tests/plugins/kv/memcached/plugin_test.go4
-rw-r--r--tests/plugins/kv/memory/configs/.rr-init.yaml5
-rw-r--r--tests/plugins/kv/memory/plugin_test.go4
-rw-r--r--tests/plugins/logger/.rr.yaml2
-rw-r--r--tests/plugins/logger/logger_test.go2
-rw-r--r--tests/plugins/metrics/.rr-test.yaml1
-rw-r--r--tests/plugins/metrics/metrics_test.go78
-rw-r--r--tests/plugins/mocks/mock_log.go150
-rw-r--r--tests/plugins/redis/redis_plugin_test.go2
-rw-r--r--tests/plugins/reload/reload_plugin_test.go2
-rw-r--r--tests/plugins/resetter/.rr-resetter.yaml3
-rw-r--r--tests/plugins/resetter/resetter_test.go23
-rw-r--r--tests/plugins/resetter/test_plugin.go8
-rw-r--r--tests/plugins/rpc/rpc_test.go2
-rw-r--r--tests/plugins/server/plugin_pipes.go21
-rw-r--r--tests/plugins/server/plugin_sockets.go8
-rw-r--r--tests/plugins/server/plugin_tcp.go8
-rw-r--r--tests/plugins/server/server_plugin_test.go2
-rw-r--r--tests/plugins/static/configs/.rr-http-static-disabled.yaml7
-rw-r--r--tests/plugins/static/configs/.rr-http-static-files-disable.yaml6
-rw-r--r--tests/plugins/static/static_plugin_test.go7
48 files changed, 456 insertions, 365 deletions
diff --git a/tests/composer.json b/tests/composer.json
index d4f32be5..889b6808 100644
--- a/tests/composer.json
+++ b/tests/composer.json
@@ -1,5 +1,6 @@
{
"minimum-stability": "beta",
+ "prefer-stable": true,
"require": {
"nyholm/psr7": "^1.3",
"spiral/roadrunner": "^2.0",
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 36130382..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"
@@ -15,7 +14,7 @@ status:
address: "127.0.0.1:34333"
logs:
mode: development
- level: debug
+ level: error
http:
debug: true
address: 127.0.0.1:11933
diff --git a/tests/plugins/checker/plugin_test.go b/tests/plugins/checker/plugin_test.go
index c346d91a..5e391158 100644
--- a/tests/plugins/checker/plugin_test.go
+++ b/tests/plugins/checker/plugin_test.go
@@ -12,7 +12,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/checker"
"github.com/spiral/roadrunner/v2/plugins/config"
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/config/config_test.go b/tests/plugins/config/config_test.go
index 6d95ba70..364960db 100755
--- a/tests/plugins/config/config_test.go
+++ b/tests/plugins/config/config_test.go
@@ -6,7 +6,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/stretchr/testify/assert"
)
diff --git a/tests/plugins/gzip/plugin_test.go b/tests/plugins/gzip/plugin_test.go
index d525dcc6..3e3db0f8 100644
--- a/tests/plugins/gzip/plugin_test.go
+++ b/tests/plugins/gzip/plugin_test.go
@@ -7,9 +7,10 @@ import (
"sync"
"syscall"
"testing"
+ "time"
"github.com/golang/mock/gomock"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/gzip"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -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 a2ad3357..49d86b00 100644
--- a/tests/plugins/headers/headers_plugin_test.go
+++ b/tests/plugins/headers/headers_plugin_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/headers"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -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..ab42f4fc 100644
--- a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
@@ -26,11 +26,10 @@ http:
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
- # rootCa: root.crt
+ # root_ca: root.crt
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..bd5d01bd 100644
--- a/tests/plugins/http/configs/.rr-fcgi.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi.yaml
@@ -26,11 +26,10 @@ http:
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
- # rootCa: root.crt
+ # root_ca: root.crt
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-supervised-pool.yaml b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml
new file mode 100644
index 00000000..3e392577
--- /dev/null
+++ b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml
@@ -0,0 +1,33 @@
+rpc:
+ listen: tcp://127.0.0.1:15432
+server:
+ command: "php ../../http/client.php echo pipes"
+ user: ""
+ group: ""
+ env:
+ "RR_HTTP": "true"
+ relay: "pipes"
+ relay_timeout: "20s"
+
+http:
+ debug: true
+ address: 127.0.0.1:18888
+ max_request_size: 1024
+ middleware: [ "" ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ num_workers: 1
+ max_jobs: 0
+ allocate_timeout: 60s
+ destroy_timeout: 60s
+ supervisor:
+ watch_tick: 1s
+ ttl: 0
+ idle_ttl: 5s
+ exec_ttl: 10s
+ max_worker_memory: 100
+logs:
+ mode: development
+ level: error \ No newline at end of file
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..77132b43 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"
@@ -30,11 +29,10 @@ http:
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
- # rootCa: root.crt
+ # root_ca: root.crt
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/http/handler_test.go b/tests/plugins/http/handler_test.go
index ee6f795d..e47dbd44 100644
--- a/tests/plugins/http/handler_test.go
+++ b/tests/plugins/http/handler_test.go
@@ -10,8 +10,8 @@ import (
"runtime"
"strings"
- "github.com/spiral/roadrunner/v2/pkg/pipe"
- poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/transport/pipe"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/http/config"
"github.com/stretchr/testify/assert"
@@ -23,10 +23,10 @@ import (
)
func TestHandler_Echo(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "echo", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -38,7 +38,7 @@ func TestHandler_Echo(t *testing.T) {
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -74,10 +74,10 @@ func Test_HandlerErrors(t *testing.T) {
}
func TestHandler_Headers(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "header", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -86,13 +86,13 @@ func TestHandler_Headers(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8078", Handler: h}
@@ -135,10 +135,10 @@ func TestHandler_Headers(t *testing.T) {
}
func TestHandler_Empty_User_Agent(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "user-agent", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -147,13 +147,13 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8088", Handler: h}
@@ -195,10 +195,10 @@ func TestHandler_Empty_User_Agent(t *testing.T) {
}
func TestHandler_User_Agent(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "user-agent", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -207,13 +207,13 @@ func TestHandler_User_Agent(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8088", Handler: h}
@@ -255,10 +255,10 @@ func TestHandler_User_Agent(t *testing.T) {
}
func TestHandler_Cookies(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "cookie", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -267,13 +267,13 @@ func TestHandler_Cookies(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8079", Handler: h}
@@ -320,10 +320,10 @@ func TestHandler_Cookies(t *testing.T) {
}
func TestHandler_JsonPayload_POST(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "payload", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -332,13 +332,13 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8090", Handler: h}
@@ -384,10 +384,10 @@ func TestHandler_JsonPayload_POST(t *testing.T) {
}
func TestHandler_JsonPayload_PUT(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "payload", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -396,13 +396,13 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8081", Handler: h}
@@ -444,10 +444,10 @@ func TestHandler_JsonPayload_PUT(t *testing.T) {
}
func TestHandler_JsonPayload_PATCH(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "payload", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -456,13 +456,13 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8082", Handler: h}
@@ -504,10 +504,10 @@ func TestHandler_JsonPayload_PATCH(t *testing.T) {
}
func TestHandler_FormData_POST(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -516,13 +516,13 @@ func TestHandler_FormData_POST(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8083", Handler: h}
@@ -577,10 +577,10 @@ func TestHandler_FormData_POST(t *testing.T) {
}
func TestHandler_FormData_POST_Overwrite(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -589,13 +589,13 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8083", Handler: h}
@@ -650,10 +650,10 @@ func TestHandler_FormData_POST_Overwrite(t *testing.T) {
}
func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -662,13 +662,13 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8083", Handler: h}
@@ -722,10 +722,10 @@ func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
}
func TestHandler_FormData_PUT(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -734,13 +734,13 @@ func TestHandler_FormData_PUT(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":17834", Handler: h}
@@ -794,10 +794,10 @@ func TestHandler_FormData_PUT(t *testing.T) {
}
func TestHandler_FormData_PATCH(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -806,13 +806,13 @@ func TestHandler_FormData_PATCH(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8085", Handler: h}
@@ -866,10 +866,10 @@ func TestHandler_FormData_PATCH(t *testing.T) {
}
func TestHandler_Multipart_POST(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -878,13 +878,13 @@ func TestHandler_Multipart_POST(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8019", Handler: h}
@@ -980,10 +980,10 @@ func TestHandler_Multipart_POST(t *testing.T) {
}
func TestHandler_Multipart_PUT(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -992,13 +992,13 @@ func TestHandler_Multipart_PUT(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8020", Handler: h}
@@ -1094,10 +1094,10 @@ func TestHandler_Multipart_PUT(t *testing.T) {
}
func TestHandler_Multipart_PATCH(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "data", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1106,13 +1106,13 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8021", Handler: h}
@@ -1210,10 +1210,10 @@ func TestHandler_Multipart_PATCH(t *testing.T) {
}
func TestHandler_Error(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "error", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1222,13 +1222,13 @@ func TestHandler_Error(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1256,10 +1256,10 @@ func TestHandler_Error(t *testing.T) {
}
func TestHandler_Error2(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "error2", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1268,13 +1268,13 @@ func TestHandler_Error2(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1302,10 +1302,10 @@ func TestHandler_Error2(t *testing.T) {
}
func TestHandler_Error3(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "pid", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1314,13 +1314,13 @@ func TestHandler_Error3(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1361,10 +1361,10 @@ func TestHandler_Error3(t *testing.T) {
}
func TestHandler_ResponseDuration(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "echo", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1373,13 +1373,13 @@ func TestHandler_ResponseDuration(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1422,10 +1422,10 @@ func TestHandler_ResponseDuration(t *testing.T) {
}
func TestHandler_ResponseDurationDelayed(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "echoDelay", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1434,13 +1434,13 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1482,10 +1482,10 @@ func TestHandler_ResponseDurationDelayed(t *testing.T) {
}
func TestHandler_ErrorDuration(t *testing.T) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "error", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1494,13 +1494,13 @@ func TestHandler_ErrorDuration(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(t, err)
hs := &http.Server{Addr: ":8177", Handler: h}
@@ -1556,10 +1556,10 @@ func TestHandler_IP(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, cidrs)
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "ip", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1568,13 +1568,13 @@ func TestHandler_IP(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, cidrs, pool)
+ }, cidrs, p)
assert.NoError(t, err)
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
@@ -1617,10 +1617,10 @@ func TestHandler_XRealIP(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, cidrs)
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "ip", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1629,13 +1629,13 @@ func TestHandler_XRealIP(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, cidrs, pool)
+ }, cidrs, p)
assert.NoError(t, err)
hs := &http.Server{Addr: "127.0.0.1:8179", Handler: h}
@@ -1683,10 +1683,10 @@ func TestHandler_XForwardedFor(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, cidrs)
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "ip", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1695,13 +1695,13 @@ func TestHandler_XForwardedFor(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, cidrs, pool)
+ }, cidrs, p)
assert.NoError(t, err)
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
@@ -1748,10 +1748,10 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, cidrs)
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "ip", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
+ pool.Config{
NumWorkers: 1,
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
@@ -1760,13 +1760,13 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
t.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, cidrs, pool)
+ }, cidrs, p)
assert.NoError(t, err)
hs := &http.Server{Addr: "127.0.0.1:8177", Handler: h}
@@ -1796,11 +1796,11 @@ func TestHandler_XForwardedFor_NotTrustedRemoteIp(t *testing.T) {
}
func BenchmarkHandler_Listen_Echo(b *testing.B) {
- pool, err := poolImpl.Initialize(context.Background(),
+ p, err := pool.Initialize(context.Background(),
func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "echo", "pipes") },
pipe.NewPipeFactory(),
- poolImpl.Config{
- NumWorkers: int64(runtime.NumCPU()),
+ pool.Config{
+ NumWorkers: uint64(runtime.NumCPU()),
AllocateTimeout: time.Second * 1000,
DestroyTimeout: time.Second * 1000,
})
@@ -1808,13 +1808,13 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) {
b.Fatal(err)
}
defer func() {
- pool.Destroy(context.Background())
+ p.Destroy(context.Background())
}()
h, err := httpPlugin.NewHandler(1024, config.Uploads{
Dir: os.TempDir(),
Forbid: []string{},
- }, nil, pool)
+ }, nil, p)
assert.NoError(b, err)
hs := &http.Server{Addr: ":8177", Handler: h}
diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go
index 72ae05a0..4f99dbbb 100644
--- a/tests/plugins/http/http_plugin_test.go
+++ b/tests/plugins/http/http_plugin_test.go
@@ -17,9 +17,9 @@ import (
"time"
"github.com/golang/mock/gomock"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
- "github.com/spiral/roadrunner/v2/interfaces/events"
+ "github.com/spiral/roadrunner/v2/pkg/events"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/informer"
"github.com/spiral/roadrunner/v2/plugins/logger"
@@ -1221,6 +1221,125 @@ func TestHttpBrokenPipes(t *testing.T) {
assert.Error(t, err)
}
+func TestHTTPSupervisedPool(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-http-supervised-pool.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ &informer.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ stopCh := make(chan struct{}, 1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 1)
+ t.Run("HTTPEchoTest", echoHTTP2)
+ // worker should be destructed (idle_ttl)
+ t.Run("HTTPInformerCompareWorkersTest", informerTest2)
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func echoHTTP2(t *testing.T) {
+ req, err := http.NewRequest("GET", "http://localhost:18888?hello=world", nil)
+ assert.NoError(t, err)
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+ assert.Equal(t, 201, r.StatusCode)
+ assert.Equal(t, "WORLD", string(b))
+
+ err = r.Body.Close()
+ assert.NoError(t, err)
+}
+
+// get worker
+// sleep
+// supervisor destroy worker
+// compare pid's
+func informerTest2(t *testing.T) {
+ conn, err := net.Dial("tcp", "127.0.0.1:15432")
+ assert.NoError(t, err)
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
+ pid := 0
+ // WorkerList contains list of workers.
+ list := struct {
+ // Workers is list of workers.
+ Workers []tools.ProcessState `json:"workers"`
+ }{}
+
+ err = client.Call("informer.Workers", "http", &list)
+ assert.NoError(t, err)
+ assert.Len(t, list.Workers, 1)
+ // save the pid
+ pid = list.Workers[0].Pid
+ time.Sleep(time.Second * 10)
+
+ list = struct {
+ // Workers is list of workers.
+ Workers []tools.ProcessState `json:"workers"`
+ }{}
+
+ err = client.Call("informer.Workers", "http", &list)
+ assert.NoError(t, err)
+ assert.Len(t, list.Workers, 1)
+ assert.NotEqual(t, list.Workers[0].Pid, pid)
+}
+
func get(url string) (string, *http.Response, error) {
r, err := http.Get(url) //nolint:gosec
if err != nil {
diff --git a/tests/plugins/http/uploads_test.go b/tests/plugins/http/uploads_test.go
index e03638d2..dd986902 100644
--- a/tests/plugins/http/uploads_test.go
+++ b/tests/plugins/http/uploads_test.go
@@ -16,8 +16,8 @@ import (
"time"
j "github.com/json-iterator/go"
- "github.com/spiral/roadrunner/v2/pkg/pipe"
poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/transport/pipe"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/http/config"
"github.com/stretchr/testify/assert"
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 d9fc2143..31e14ff4 100644
--- a/tests/plugins/informer/informer_test.go
+++ b/tests/plugins/informer/informer_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ 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/informer"
@@ -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/informer/test_plugin.go b/tests/plugins/informer/test_plugin.go
index ba281d02..2300de89 100644
--- a/tests/plugins/informer/test_plugin.go
+++ b/tests/plugins/informer/test_plugin.go
@@ -4,22 +4,22 @@ import (
"context"
"time"
- "github.com/spiral/roadrunner/v2/interfaces/worker"
- poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/worker"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/server"
)
-var testPoolConfig = poolImpl.Config{
+var testPoolConfig = pool.Config{
NumWorkers: 10,
MaxJobs: 100,
AllocateTimeout: time.Second * 10,
DestroyTimeout: time.Second * 10,
- Supervisor: &poolImpl.SupervisorConfig{
- WatchTick: 60,
- TTL: 1000,
- IdleTTL: 10,
- ExecTTL: 10,
+ Supervisor: &pool.SupervisorConfig{
+ WatchTick: 60 * time.Second,
+ TTL: 1000 * time.Second,
+ IdleTTL: 10 * time.Second,
+ ExecTTL: 10 * time.Second,
MaxWorkerMemory: 1000,
},
}
@@ -50,10 +50,16 @@ func (p1 *Plugin1) Name() string {
}
func (p1 *Plugin1) Workers() []worker.BaseProcess {
- pool, err := p1.server.NewWorkerPool(context.Background(), testPoolConfig, nil)
+ p, err := p1.server.NewWorkerPool(context.Background(), testPoolConfig, nil)
if err != nil {
panic(err)
}
- return pool.Workers()
+ workers := p.Workers()
+ baseWorkers := make([]worker.BaseProcess, 0, len(workers))
+ for i := 0; i < len(workers); i++ {
+ baseWorkers = append(baseWorkers, worker.FromSync(workers[i].(*worker.SyncWorkerImpl)))
+ }
+
+ return baseWorkers
}
diff --git a/tests/plugins/kv/boltdb/configs/.rr-init.yaml b/tests/plugins/kv/boltdb/configs/.rr-init.yaml
index 8cfa20e9..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"
@@ -13,7 +12,7 @@ server:
logs:
mode: development
- level: debug
+ level: error
http:
address: 127.0.0.1:44933
diff --git a/tests/plugins/kv/boltdb/plugin_test.go b/tests/plugins/kv/boltdb/plugin_test.go
index 5548402d..3a4542ff 100644
--- a/tests/plugins/kv/boltdb/plugin_test.go
+++ b/tests/plugins/kv/boltdb/plugin_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -23,7 +23,7 @@ import (
)
func TestBoltDb(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
assert.NoError(t, err)
cfg := &config.Viper{
diff --git a/tests/plugins/kv/memcached/configs/.rr-init.yaml b/tests/plugins/kv/memcached/configs/.rr-init.yaml
index 66ed75cf..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"
@@ -13,7 +12,7 @@ server:
logs:
mode: development
- level: debug
+ level: error
http:
address: 127.0.0.1:44933
diff --git a/tests/plugins/kv/memcached/plugin_test.go b/tests/plugins/kv/memcached/plugin_test.go
index d4cb58bb..3878ef67 100644
--- a/tests/plugins/kv/memcached/plugin_test.go
+++ b/tests/plugins/kv/memcached/plugin_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -23,7 +23,7 @@ import (
)
func TestMemcache(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
assert.NoError(t, err)
cfg := &config.Viper{
diff --git a/tests/plugins/kv/memory/configs/.rr-init.yaml b/tests/plugins/kv/memory/configs/.rr-init.yaml
index e352fad2..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"
@@ -13,7 +12,7 @@ server:
logs:
mode: development
- level: debug
+ level: error
http:
address: 127.0.0.1:44933
@@ -39,7 +38,5 @@ http:
# in memory KV driver
memory:
- enabled:
- true
# keys ttl check interval
interval: 1
diff --git a/tests/plugins/kv/memory/plugin_test.go b/tests/plugins/kv/memory/plugin_test.go
index ee01fabb..528403d0 100644
--- a/tests/plugins/kv/memory/plugin_test.go
+++ b/tests/plugins/kv/memory/plugin_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -23,7 +23,7 @@ import (
)
func TestInMemory(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel))
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
assert.NoError(t, err)
cfg := &config.Viper{
diff --git a/tests/plugins/logger/.rr.yaml b/tests/plugins/logger/.rr.yaml
index cb555ec3..5ab359d3 100644
--- a/tests/plugins/logger/.rr.yaml
+++ b/tests/plugins/logger/.rr.yaml
@@ -1,3 +1,3 @@
logs:
mode: development
- level: debug \ No newline at end of file
+ level: error \ No newline at end of file
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index cc788be3..63f233ee 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -6,7 +6,7 @@ import (
"sync"
"testing"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/stretchr/testify/assert"
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 c94d51bc..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/spiral/endure"
+ "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/redis/redis_plugin_test.go b/tests/plugins/redis/redis_plugin_test.go
index eba05752..96a191a1 100644
--- a/tests/plugins/redis/redis_plugin_test.go
+++ b/tests/plugins/redis/redis_plugin_test.go
@@ -10,7 +10,7 @@ import (
"github.com/alicebob/miniredis/v2"
"github.com/golang/mock/gomock"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/redis"
"github.com/spiral/roadrunner/v2/tests/mocks"
diff --git a/tests/plugins/reload/reload_plugin_test.go b/tests/plugins/reload/reload_plugin_test.go
index 81ac3c44..9007541b 100644
--- a/tests/plugins/reload/reload_plugin_test.go
+++ b/tests/plugins/reload/reload_plugin_test.go
@@ -14,7 +14,7 @@ import (
"time"
"github.com/golang/mock/gomock"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
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 89dd43c7..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/spiral/endure"
+ "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{},
diff --git a/tests/plugins/resetter/test_plugin.go b/tests/plugins/resetter/test_plugin.go
index 7d53bca0..61942516 100644
--- a/tests/plugins/resetter/test_plugin.go
+++ b/tests/plugins/resetter/test_plugin.go
@@ -15,10 +15,10 @@ var testPoolConfig = poolImpl.Config{
AllocateTimeout: time.Second * 10,
DestroyTimeout: time.Second * 10,
Supervisor: &poolImpl.SupervisorConfig{
- WatchTick: 60,
- TTL: 1000,
- IdleTTL: 10,
- ExecTTL: 10,
+ WatchTick: 60 * time.Second,
+ TTL: 1000 * time.Second,
+ IdleTTL: 10 * time.Second,
+ ExecTTL: 10 * time.Second,
MaxWorkerMemory: 1000,
},
}
diff --git a/tests/plugins/rpc/rpc_test.go b/tests/plugins/rpc/rpc_test.go
index 98959b28..49d3b3f1 100644
--- a/tests/plugins/rpc/rpc_test.go
+++ b/tests/plugins/rpc/rpc_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
diff --git a/tests/plugins/server/plugin_pipes.go b/tests/plugins/server/plugin_pipes.go
index 5eb2fed1..af34b4d3 100644
--- a/tests/plugins/server/plugin_pipes.go
+++ b/tests/plugins/server/plugin_pipes.go
@@ -5,9 +5,8 @@ import (
"time"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/pkg/payload"
- poolImpl "github.com/spiral/roadrunner/v2/pkg/pool"
+ "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/worker"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -16,16 +15,16 @@ import (
const ConfigSection = "server"
const Response = "test"
-var testPoolConfig = poolImpl.Config{
+var testPoolConfig = pool.Config{
NumWorkers: 10,
MaxJobs: 100,
AllocateTimeout: time.Second * 10,
DestroyTimeout: time.Second * 10,
- Supervisor: &poolImpl.SupervisorConfig{
- WatchTick: 60,
- TTL: 1000,
- IdleTTL: 10,
- ExecTTL: 10,
+ Supervisor: &pool.SupervisorConfig{
+ WatchTick: 60 * time.Second,
+ TTL: 1000 * time.Second,
+ IdleTTL: 10 * time.Second,
+ ExecTTL: 10 * time.Second,
MaxWorkerMemory: 1000,
},
}
@@ -80,11 +79,7 @@ func (f *Foo) Serve() chan error {
}
// test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
+ sw := worker.From(w)
rsp, err := sw.Exec(r)
if err != nil {
diff --git a/tests/plugins/server/plugin_sockets.go b/tests/plugins/server/plugin_sockets.go
index ede67ded..0b2857e3 100644
--- a/tests/plugins/server/plugin_sockets.go
+++ b/tests/plugins/server/plugin_sockets.go
@@ -4,8 +4,8 @@ import (
"context"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/pkg/payload"
+ "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/worker"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -60,11 +60,7 @@ func (f *Foo2) Serve() chan error {
}
// test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
+ sw := worker.From(w)
rsp, err := sw.Exec(r)
if err != nil {
diff --git a/tests/plugins/server/plugin_tcp.go b/tests/plugins/server/plugin_tcp.go
index 98c13b2b..ef4cea39 100644
--- a/tests/plugins/server/plugin_tcp.go
+++ b/tests/plugins/server/plugin_tcp.go
@@ -4,8 +4,8 @@ import (
"context"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/interfaces/pool"
"github.com/spiral/roadrunner/v2/pkg/payload"
+ "github.com/spiral/roadrunner/v2/pkg/pool"
"github.com/spiral/roadrunner/v2/pkg/worker"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -60,11 +60,7 @@ func (f *Foo3) Serve() chan error {
}
// test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
+ sw := worker.From(w)
rsp, err := sw.Exec(r)
if err != nil {
diff --git a/tests/plugins/server/server_plugin_test.go b/tests/plugins/server/server_plugin_test.go
index d63b0ccd..f600832a 100644
--- a/tests/plugins/server/server_plugin_test.go
+++ b/tests/plugins/server/server_plugin_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"time"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
"github.com/spiral/roadrunner/v2/plugins/server"
diff --git a/tests/plugins/static/configs/.rr-http-static-disabled.yaml b/tests/plugins/static/configs/.rr-http-static-disabled.yaml
index e31baffc..9f04b8a9 100644
--- a/tests/plugins/static/configs/.rr-http-static-disabled.yaml
+++ b/tests/plugins/static/configs/.rr-http-static-disabled.yaml
@@ -11,7 +11,7 @@ http:
debug: true
address: 127.0.0.1:21234
max_request_size: 1024
- middleware: [ "gzip", "static" ]
+ middleware: [ "gzip" ]
trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
uploads:
forbid: [ ".php", ".exe", ".bat" ]
@@ -19,10 +19,9 @@ http:
dir: "abc" #not exists
forbid: [ ".php", ".htaccess" ]
request:
- "Example-Request-Header": "Value"
- # Automatically add headers to every response.
+ Example-Request-Header: "Value"
response:
- "X-Powered-By": "RoadRunner"
+ X-Powered-By: "RoadRunner"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/plugins/static/configs/.rr-http-static-files-disable.yaml b/tests/plugins/static/configs/.rr-http-static-files-disable.yaml
index deb408db..3d4d50b9 100644
--- a/tests/plugins/static/configs/.rr-http-static-files-disable.yaml
+++ b/tests/plugins/static/configs/.rr-http-static-files-disable.yaml
@@ -11,7 +11,7 @@ http:
debug: true
address: 127.0.0.1:45877
max_request_size: 1024
- middleware: [ "gzip", "static" ]
+ middleware: [ "gzip" ]
trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
uploads:
forbid: [ ".php", ".exe", ".bat" ]
@@ -19,10 +19,10 @@ http:
dir: "../../../tests"
forbid: [ ".php" ]
request:
- "Example-Request-Header": "Value"
+ Example-Request-Header: "Value"
# Automatically add headers to every response.
response:
- "X-Powered-By": "RoadRunner"
+ X-Powered-By: "RoadRunner"
pool:
num_workers: 2
max_jobs: 0
diff --git a/tests/plugins/static/static_plugin_test.go b/tests/plugins/static/static_plugin_test.go
index 49721e44..d43ef765 100644
--- a/tests/plugins/static/static_plugin_test.go
+++ b/tests/plugins/static/static_plugin_test.go
@@ -13,7 +13,7 @@ import (
"time"
"github.com/golang/mock/gomock"
- "github.com/spiral/endure"
+ endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/gzip"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
@@ -209,8 +209,9 @@ func TestStaticDisabled(t *testing.T) {
func staticDisabled(t *testing.T) {
_, r, err := get("http://localhost:21234/sample.txt") //nolint:bodyclose
- assert.Error(t, err)
- assert.Nil(t, r)
+ assert.NoError(t, err)
+ assert.NotNil(t, r)
+ assert.Empty(t, r.Header.Get("X-Powered-By"))
}
func TestStaticFilesDisabled(t *testing.T) {