summaryrefslogtreecommitdiff
path: root/plugins/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/server/tests')
-rw-r--r--plugins/server/tests/configs/.rr-no-app-section.yaml12
-rw-r--r--plugins/server/tests/configs/.rr-sockets.yaml12
-rw-r--r--plugins/server/tests/configs/.rr-tcp.yaml12
-rw-r--r--plugins/server/tests/configs/.rr-wrong-command.yaml12
-rw-r--r--plugins/server/tests/configs/.rr-wrong-relay.yaml12
-rw-r--r--plugins/server/tests/configs/.rr.yaml12
-rw-r--r--plugins/server/tests/plugin_pipes.go134
-rw-r--r--plugins/server/tests/plugin_sockets.go114
-rw-r--r--plugins/server/tests/plugin_tcp.go114
-rw-r--r--plugins/server/tests/server_test.go356
-rw-r--r--plugins/server/tests/socket.php25
-rw-r--r--plugins/server/tests/tcp.php20
12 files changed, 0 insertions, 835 deletions
diff --git a/plugins/server/tests/configs/.rr-no-app-section.yaml b/plugins/server/tests/configs/.rr-no-app-section.yaml
deleted file mode 100644
index 5266e83d..00000000
--- a/plugins/server/tests/configs/.rr-no-app-section.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php ../../../tests/client.php echo pipes"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "pipes"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/configs/.rr-sockets.yaml b/plugins/server/tests/configs/.rr-sockets.yaml
deleted file mode 100644
index 6b5b6bf5..00000000
--- a/plugins/server/tests/configs/.rr-sockets.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php socket.php"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "unix://unix.sock"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/configs/.rr-tcp.yaml b/plugins/server/tests/configs/.rr-tcp.yaml
deleted file mode 100644
index ee1d450a..00000000
--- a/plugins/server/tests/configs/.rr-tcp.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php tcp.php"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "tcp://localhost:9999"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/configs/.rr-wrong-command.yaml b/plugins/server/tests/configs/.rr-wrong-command.yaml
deleted file mode 100644
index e66349dd..00000000
--- a/plugins/server/tests/configs/.rr-wrong-command.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php some_absent_file.php"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "pipes"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/configs/.rr-wrong-relay.yaml b/plugins/server/tests/configs/.rr-wrong-relay.yaml
deleted file mode 100644
index 98894c7a..00000000
--- a/plugins/server/tests/configs/.rr-wrong-relay.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php ../../../tests/client.php echo pipes"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "pupes"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/configs/.rr.yaml b/plugins/server/tests/configs/.rr.yaml
deleted file mode 100644
index 5266e83d..00000000
--- a/plugins/server/tests/configs/.rr.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-server:
- command: "php ../../../tests/client.php echo pipes"
- user: ""
- group: ""
- env:
- "RR_CONFIG": "/some/place/on/the/C134"
- "RR_CONFIG2": "C138"
- relay: "pipes"
- relayTimeout: "20s"
-logs:
- mode: development
- level: error \ No newline at end of file
diff --git a/plugins/server/tests/plugin_pipes.go b/plugins/server/tests/plugin_pipes.go
deleted file mode 100644
index 9a7d3e3b..00000000
--- a/plugins/server/tests/plugin_pipes.go
+++ /dev/null
@@ -1,134 +0,0 @@
-package tests
-
-import (
- "context"
- "time"
-
- "github.com/spiral/errors"
- "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/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"
-)
-
-const ConfigSection = "server"
-const Response = "test"
-
-var testPoolConfig = poolImpl.Config{
- NumWorkers: 10,
- MaxJobs: 100,
- AllocateTimeout: time.Second * 10,
- DestroyTimeout: time.Second * 10,
- Supervisor: &poolImpl.SupervisorConfig{
- WatchTick: 60,
- TTL: 1000,
- IdleTTL: 10,
- ExecTTL: 10,
- MaxWorkerMemory: 1000,
- },
-}
-
-type Foo struct {
- configProvider config.Configurer
- wf server.Server
- pool pool.Pool
-}
-
-func (f *Foo) Init(p config.Configurer, workerFactory server.Server) error {
- f.configProvider = p
- f.wf = workerFactory
- return nil
-}
-
-func (f *Foo) Serve() chan error {
- const op = errors.Op("serve")
-
- // test payload for echo
- r := payload.Payload{
- Context: nil,
- Body: []byte(Response),
- }
-
- errCh := make(chan error, 1)
-
- conf := &plugin.Config{}
- var err error
- err = f.configProvider.UnmarshalKey(ConfigSection, conf)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test CMDFactory
- cmd, err := f.wf.CmdFactory(nil)
- if err != nil {
- errCh <- err
- return errCh
- }
- if cmd == nil {
- errCh <- errors.E(op, "command is nil")
- return errCh
- }
-
- // test worker creation
- w, err := f.wf.NewWorker(context.Background(), nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- rsp, err := sw.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- // should not be errors
- err = sw.Stop()
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool
- f.pool, err = f.wf.NewWorkerPool(context.Background(), testPoolConfig, nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool execution
- rsp, err = f.pool.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // echo of the "test" should be -> test
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- return errCh
-}
-
-func (f *Foo) Stop() error {
- f.pool.Destroy(context.Background())
- return nil
-}
diff --git a/plugins/server/tests/plugin_sockets.go b/plugins/server/tests/plugin_sockets.go
deleted file mode 100644
index c62871b1..00000000
--- a/plugins/server/tests/plugin_sockets.go
+++ /dev/null
@@ -1,114 +0,0 @@
-package tests
-
-import (
- "context"
-
- "github.com/spiral/errors"
- "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/pkg/payload"
- "github.com/spiral/roadrunner/v2/pkg/worker"
- plugin "github.com/spiral/roadrunner/v2/plugins/server"
-)
-
-type Foo2 struct {
- configProvider config.Configurer
- wf server.Server
- pool pool.Pool
-}
-
-func (f *Foo2) Init(p config.Configurer, workerFactory server.Server) error {
- f.configProvider = p
- f.wf = workerFactory
- return nil
-}
-
-func (f *Foo2) Serve() chan error {
- const op = errors.Op("serve")
- var err error
- errCh := make(chan error, 1)
- conf := &plugin.Config{}
-
- // test payload for echo
- r := payload.Payload{
- Context: nil,
- Body: []byte(Response),
- }
-
- err = f.configProvider.UnmarshalKey(ConfigSection, conf)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test CMDFactory
- cmd, err := f.wf.CmdFactory(nil)
- if err != nil {
- errCh <- err
- return errCh
- }
- if cmd == nil {
- errCh <- errors.E(op, "command is nil")
- return errCh
- }
-
- // test worker creation
- w, err := f.wf.NewWorker(context.Background(), nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- rsp, err := sw.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- // should not be errors
- err = sw.Stop()
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool
- f.pool, err = f.wf.NewWorkerPool(context.Background(), testPoolConfig, nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool execution
- rsp, err = f.pool.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // echo of the "test" should be -> test
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- return errCh
-}
-
-func (f *Foo2) Stop() error {
- f.pool.Destroy(context.Background())
- return nil
-}
diff --git a/plugins/server/tests/plugin_tcp.go b/plugins/server/tests/plugin_tcp.go
deleted file mode 100644
index 781b87d0..00000000
--- a/plugins/server/tests/plugin_tcp.go
+++ /dev/null
@@ -1,114 +0,0 @@
-package tests
-
-import (
- "context"
-
- "github.com/spiral/errors"
- "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/pkg/payload"
- "github.com/spiral/roadrunner/v2/pkg/worker"
- plugin "github.com/spiral/roadrunner/v2/plugins/server"
-)
-
-type Foo3 struct {
- configProvider config.Configurer
- wf server.Server
- pool pool.Pool
-}
-
-func (f *Foo3) Init(p config.Configurer, workerFactory server.Server) error {
- f.configProvider = p
- f.wf = workerFactory
- return nil
-}
-
-func (f *Foo3) Serve() chan error {
- const op = errors.Op("serve")
- var err error
- errCh := make(chan error, 1)
- conf := &plugin.Config{}
-
- // test payload for echo
- r := payload.Payload{
- Context: nil,
- Body: []byte(Response),
- }
-
- err = f.configProvider.UnmarshalKey(ConfigSection, conf)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test CMDFactory
- cmd, err := f.wf.CmdFactory(nil)
- if err != nil {
- errCh <- err
- return errCh
- }
- if cmd == nil {
- errCh <- errors.E(op, "command is nil")
- return errCh
- }
-
- // test worker creation
- w, err := f.wf.NewWorker(context.Background(), nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test that our worker is functional
- sw, err := worker.From(w)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- rsp, err := sw.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- // should not be errors
- err = sw.Stop()
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool
- f.pool, err = f.wf.NewWorkerPool(context.Background(), testPoolConfig, nil)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // test pool execution
- rsp, err = f.pool.Exec(r)
- if err != nil {
- errCh <- err
- return errCh
- }
-
- // echo of the "test" should be -> test
- if string(rsp.Body) != Response {
- errCh <- errors.E("response from worker is wrong", errors.Errorf("response: %s", rsp.Body))
- return errCh
- }
-
- return errCh
-}
-
-func (f *Foo3) Stop() error {
- f.pool.Destroy(context.Background())
- return nil
-}
diff --git a/plugins/server/tests/server_test.go b/plugins/server/tests/server_test.go
deleted file mode 100644
index faf01b11..00000000
--- a/plugins/server/tests/server_test.go
+++ /dev/null
@@ -1,356 +0,0 @@
-package tests
-
-import (
- "os"
- "os/signal"
- "testing"
- "time"
-
- "github.com/spiral/endure"
- "github.com/spiral/roadrunner/v2/plugins/config"
- "github.com/spiral/roadrunner/v2/plugins/logger"
- "github.com/spiral/roadrunner/v2/plugins/server"
- "github.com/stretchr/testify/assert"
-)
-
-func TestAppPipes(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- errCh, err := container.Serve()
- if err != nil {
- t.Fatal(err)
- }
-
- // stop by CTRL+C
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
-
- // stop after 10 seconds
- tt := time.NewTicker(time.Second * 10)
-
- for {
- select {
- case e := <-errCh:
- assert.NoError(t, e.Error)
- assert.NoError(t, container.Stop())
- return
- case <-c:
- er := container.Stop()
- if er != nil {
- panic(er)
- }
- return
- case <-tt.C:
- tt.Stop()
- assert.NoError(t, container.Stop())
- return
- }
- }
-}
-
-func TestAppSockets(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr-sockets.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo2{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- errCh, err := container.Serve()
- if err != nil {
- t.Fatal(err)
- }
-
- // stop by CTRL+C
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
-
- // stop after 10 seconds
- tt := time.NewTicker(time.Second * 10)
-
- for {
- select {
- case e := <-errCh:
- assert.NoError(t, e.Error)
- assert.NoError(t, container.Stop())
- return
- case <-c:
- er := container.Stop()
- if er != nil {
- panic(er)
- }
- return
- case <-tt.C:
- tt.Stop()
- assert.NoError(t, container.Stop())
- return
- }
- }
-}
-
-func TestAppTCP(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr-tcp.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo3{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- errCh, err := container.Serve()
- if err != nil {
- t.Fatal(err)
- }
-
- // stop by CTRL+C
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
-
- // stop after 10 seconds
- tt := time.NewTicker(time.Second * 10)
-
- for {
- select {
- case e := <-errCh:
- assert.NoError(t, e.Error)
- assert.NoError(t, container.Stop())
- return
- case <-c:
- er := container.Stop()
- if er != nil {
- panic(er)
- }
- return
- case <-tt.C:
- tt.Stop()
- assert.NoError(t, container.Stop())
- return
- }
- }
-}
-
-func TestAppWrongConfig(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rrrrrrrrrr.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo3{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- assert.Error(t, container.Init())
-}
-
-func TestAppWrongRelay(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr-wrong-relay.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo3{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- assert.Error(t, err)
-
- _, err = container.Serve()
- assert.Error(t, err)
-}
-
-func TestAppWrongCommand(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr-wrong-command.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo3{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = container.Serve()
- assert.Error(t, err)
-}
-
-func TestAppNoAppSectionInConfig(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- // config plugin
- vp := &config.Viper{}
- vp.Path = "configs/.rr-wrong-command.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&server.Plugin{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo3{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&logger.ZapLogger{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- _, err = container.Serve()
- assert.Error(t, err)
-}
diff --git a/plugins/server/tests/socket.php b/plugins/server/tests/socket.php
deleted file mode 100644
index 1b76481a..00000000
--- a/plugins/server/tests/socket.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * @var Goridge\RelayInterface $relay
- */
-
-use Spiral\Goridge;
-use Spiral\RoadRunner;
-
-require dirname(__DIR__) . "/../../tests/vendor/autoload.php";
-
-$relay = new Goridge\SocketRelay(
- "unix.sock",
- null,
- Goridge\SocketRelay::SOCK_UNIX
- );
-
-$rr = new RoadRunner\Worker($relay);
-
-while ($in = $rr->waitPayload()) {
- try {
- $rr->send((string)$in->body);
- } catch (\Throwable $e) {
- $rr->error((string)$e);
- }
-}
diff --git a/plugins/server/tests/tcp.php b/plugins/server/tests/tcp.php
deleted file mode 100644
index c567c982..00000000
--- a/plugins/server/tests/tcp.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * @var Goridge\RelayInterface $relay
- */
-
-use Spiral\Goridge;
-use Spiral\RoadRunner;
-
-require dirname(__DIR__) . "/../../tests/vendor/autoload.php";
-
-$relay = new Goridge\SocketRelay("localhost", 9999);
-$rr = new RoadRunner\Worker($relay);
-
-while ($in = $rr->waitPayload()) {
- try {
- $rr->send((string)$in->body);
- } catch (\Throwable $e) {
- $rr->error((string)$e);
- }
-}