diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
commit | f3491c089b4da77fd8d2bc942a88b6b8d117a8a5 (patch) | |
tree | 32bfffb1f24eeee7b909747cc00a6a6b9fd3ee83 /tests/plugins/server | |
parent | 5d2cd55ab522d4f1e65a833f91146444465a32ac (diff) |
Move plugins to a separate repository
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins/server')
-rw-r--r-- | tests/plugins/server/configs/.rr-no-app-section.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/configs/.rr-sockets.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/configs/.rr-tcp.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/configs/.rr-wrong-command.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/configs/.rr-wrong-relay.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/configs/.rr.yaml | 12 | ||||
-rw-r--r-- | tests/plugins/server/plugin_pipes.go | 128 | ||||
-rw-r--r-- | tests/plugins/server/plugin_sockets.go | 109 | ||||
-rw-r--r-- | tests/plugins/server/plugin_tcp.go | 109 | ||||
-rw-r--r-- | tests/plugins/server/server_plugin_test.go | 352 | ||||
-rw-r--r-- | tests/plugins/server/socket.php | 25 | ||||
-rw-r--r-- | tests/plugins/server/tcp.php | 20 |
12 files changed, 0 insertions, 815 deletions
diff --git a/tests/plugins/server/configs/.rr-no-app-section.yaml b/tests/plugins/server/configs/.rr-no-app-section.yaml deleted file mode 100644 index d28265d5..00000000 --- a/tests/plugins/server/configs/.rr-no-app-section.yaml +++ /dev/null @@ -1,12 +0,0 @@ -server: - command: "php ../../client.php echo pipes" - user: "" - group: "" - env: - - RR_CONFIG: "/some/place/on/the/C134" - - RR_CONFIG2: "C138" - relay: "pipes" - relay_timeout: "20s" -logs: - mode: development - level: error diff --git a/tests/plugins/server/configs/.rr-sockets.yaml b/tests/plugins/server/configs/.rr-sockets.yaml deleted file mode 100644 index 4c57f36f..00000000 --- a/tests/plugins/server/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" - relay_timeout: "20s" -logs: - mode: development - level: error diff --git a/tests/plugins/server/configs/.rr-tcp.yaml b/tests/plugins/server/configs/.rr-tcp.yaml deleted file mode 100644 index 6b9c9ddb..00000000 --- a/tests/plugins/server/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://127.0.0.1:9999" - relay_timeout: "20s" -logs: - mode: development - level: error diff --git a/tests/plugins/server/configs/.rr-wrong-command.yaml b/tests/plugins/server/configs/.rr-wrong-command.yaml deleted file mode 100644 index 9d105d90..00000000 --- a/tests/plugins/server/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" - relay_timeout: "20s" -logs: - mode: development - level: error diff --git a/tests/plugins/server/configs/.rr-wrong-relay.yaml b/tests/plugins/server/configs/.rr-wrong-relay.yaml deleted file mode 100644 index c4d1edb0..00000000 --- a/tests/plugins/server/configs/.rr-wrong-relay.yaml +++ /dev/null @@ -1,12 +0,0 @@ -server: - command: "php ../../client.php echo pipes" - user: "" - group: "" - env: - - RR_CONFIG: "/some/place/on/the/C134" - - RR_CONFIG2: "C138" - relay: "pupes" - relay_timeout: "20s" -logs: - mode: development - level: error diff --git a/tests/plugins/server/configs/.rr.yaml b/tests/plugins/server/configs/.rr.yaml deleted file mode 100644 index a1484c02..00000000 --- a/tests/plugins/server/configs/.rr.yaml +++ /dev/null @@ -1,12 +0,0 @@ -server: - command: "php ../../client.php echo pipes" - user: "" - group: "" - env: - - RR_CONFIG: "/some/place/on/the/C134" - - RR_CONFIG2: "C138" - relay: "pipes" - relay_timeout: "20s" -logs: - mode: development - level: info diff --git a/tests/plugins/server/plugin_pipes.go b/tests/plugins/server/plugin_pipes.go deleted file mode 100644 index d136da1e..00000000 --- a/tests/plugins/server/plugin_pipes.go +++ /dev/null @@ -1,128 +0,0 @@ -package server - -import ( - "context" - "time" - - "github.com/spiral/errors" - "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" -) - -const ConfigSection = "server" -const Response = "test" - -var testPoolConfig = &pool.Config{ - NumWorkers: 10, - MaxJobs: 100, - AllocateTimeout: time.Second * 10, - DestroyTimeout: time.Second * 10, - Supervisor: &pool.SupervisorConfig{ - WatchTick: 60 * time.Second, - TTL: 1000 * time.Second, - IdleTTL: 10 * time.Second, - ExecTTL: 10 * time.Second, - 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 := &server.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, errors.Str("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 := worker.From(w) - - 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/tests/plugins/server/plugin_sockets.go b/tests/plugins/server/plugin_sockets.go deleted file mode 100644 index 143a604c..00000000 --- a/tests/plugins/server/plugin_sockets.go +++ /dev/null @@ -1,109 +0,0 @@ -package server - -import ( - "context" - - "github.com/spiral/errors" - "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" -) - -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 := &server.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 := worker.From(w) - - 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/tests/plugins/server/plugin_tcp.go b/tests/plugins/server/plugin_tcp.go deleted file mode 100644 index 57a2e6ea..00000000 --- a/tests/plugins/server/plugin_tcp.go +++ /dev/null @@ -1,109 +0,0 @@ -package server - -import ( - "context" - - "github.com/spiral/errors" - "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" -) - -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 := &server.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 := worker.From(w) - - 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/tests/plugins/server/server_plugin_test.go b/tests/plugins/server/server_plugin_test.go deleted file mode 100644 index 06c9eb50..00000000 --- a/tests/plugins/server/server_plugin_test.go +++ /dev/null @@ -1,352 +0,0 @@ -package server - -import ( - "os" - "os/signal" - "sync" - "testing" - "time" - - 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" - "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.RegisterAll( - vp, - &server.Plugin{}, - &Foo{}, - &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) - - tt := time.NewTimer(time.Second * 10) - wg := &sync.WaitGroup{} - wg.Add(1) - - go func() { - defer wg.Done() - defer tt.Stop() - for { - select { - case e := <-errCh: - assert.NoError(t, e.Error) - assert.NoError(t, container.Stop()) - return - case <-c: - er := container.Stop() - assert.NoError(t, er) - return - case <-tt.C: - assert.NoError(t, container.Stop()) - return - } - } - }() - - wg.Wait() -} - -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.NoError(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/tests/plugins/server/socket.php b/tests/plugins/server/socket.php deleted file mode 100644 index f90dda6f..00000000 --- a/tests/plugins/server/socket.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -require dirname(__DIR__) . "/../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->respond(new RoadRunner\Payload((string)$in->body)); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -} diff --git a/tests/plugins/server/tcp.php b/tests/plugins/server/tcp.php deleted file mode 100644 index acc1e1a5..00000000 --- a/tests/plugins/server/tcp.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -require dirname(__DIR__) . "/../vendor/autoload.php"; - -$relay = new Goridge\SocketRelay("127.0.0.1", 9999); -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->waitPayload()) { - try { - $rr->respond(new RoadRunner\Payload((string)$in->body)); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -} |