summaryrefslogtreecommitdiff
path: root/pipe_factory_test.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-17 12:13:55 +0300
committerGitHub <[email protected]>2020-12-17 12:13:55 +0300
commitee0cb478c74c393a35155c2bf51e1ef260e0e5e2 (patch)
tree2c99d4c6e2b2e9e3fa155d5d68a9d471c9aeeb9b /pipe_factory_test.go
parenta1dc59cabb6e63eab232922f4eb5a19dbd168f44 (diff)
parentedf924b37bcdad14eb31014c571ab58720aa178f (diff)
Merge pull request #452 from spiral/refactor/splitv2.0.0-alpha23
Refactor/split
Diffstat (limited to 'pipe_factory_test.go')
-rwxr-xr-xpipe_factory_test.go238
1 files changed, 0 insertions, 238 deletions
diff --git a/pipe_factory_test.go b/pipe_factory_test.go
deleted file mode 100755
index c742f522..00000000
--- a/pipe_factory_test.go
+++ /dev/null
@@ -1,238 +0,0 @@
-package roadrunner
-
-import (
- "context"
- "os/exec"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
-)
-
-func Test_Pipe_Start(t *testing.T) {
- ctx := context.Background()
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
-
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- assert.NoError(t, err)
- assert.NotNil(t, w)
-
- go func() {
- assert.NoError(t, w.Wait())
- }()
-
- assert.NoError(t, w.Stop(ctx))
-}
-
-func Test_Pipe_StartError(t *testing.T) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- err := cmd.Start()
- if err != nil {
- t.Errorf("error running the command: error %v", err)
- }
-
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- assert.Error(t, err)
- assert.Nil(t, w)
-}
-
-func Test_Pipe_PipeError(t *testing.T) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- _, err := cmd.StdinPipe()
- if err != nil {
- t.Errorf("error creating the STDIN pipe: error %v", err)
- }
-
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- assert.Error(t, err)
- assert.Nil(t, w)
-}
-
-func Test_Pipe_PipeError2(t *testing.T) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- _, err := cmd.StdinPipe()
- if err != nil {
- t.Errorf("error creating the STDIN pipe: error %v", err)
- }
-
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- assert.Error(t, err)
- assert.Nil(t, w)
-}
-
-func Test_Pipe_Failboot(t *testing.T) {
- cmd := exec.Command("php", "tests/failboot.php")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
-
- assert.Nil(t, w)
- assert.Error(t, err)
- assert.Contains(t, err.Error(), "failboot")
-}
-
-func Test_Pipe_Invalid(t *testing.T) {
- cmd := exec.Command("php", "tests/invalid.php")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- assert.Error(t, err)
- assert.Nil(t, w)
-}
-
-func Test_Pipe_Echo(t *testing.T) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- if err != nil {
- t.Fatal(err)
- }
- defer func() {
- err = w.Stop(ctx)
- if err != nil {
- t.Errorf("error stopping the WorkerProcess: error %v", err)
- }
- }()
-
- sw, err := NewSyncWorker(w)
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := sw.Exec(Payload{Body: []byte("hello")})
-
- assert.NoError(t, err)
- assert.NotNil(t, res)
- assert.NotNil(t, res.Body)
- assert.Empty(t, res.Context)
-
- assert.Equal(t, "hello", res.String())
-}
-
-func Test_Pipe_Broken(t *testing.T) {
- cmd := exec.Command("php", "tests/client.php", "broken", "pipes")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- if err != nil {
- t.Fatal(err)
- }
- defer func() {
- time.Sleep(time.Second)
- err = w.Stop(ctx)
- assert.Error(t, err)
- }()
-
- sw, err := NewSyncWorker(w)
- if err != nil {
- t.Fatal(err)
- }
-
- res, err := sw.Exec(Payload{Body: []byte("hello")})
-
- assert.Error(t, err)
- assert.Nil(t, res.Body)
- assert.Nil(t, res.Context)
-}
-
-func Benchmark_Pipe_SpawnWorker_Stop(b *testing.B) {
- f := NewPipeFactory()
- for n := 0; n < b.N; n++ {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- w, _ := f.SpawnWorkerWithContext(context.Background(), cmd)
- go func() {
- if w.Wait() != nil {
- b.Fail()
- }
- }()
-
- err := w.Stop(context.Background())
- if err != nil {
- b.Errorf("error stopping the worker: error %v", err)
- }
- }
-}
-
-func Benchmark_Pipe_Worker_ExecEcho(b *testing.B) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
-
- w, _ := NewPipeFactory().SpawnWorkerWithContext(context.Background(), cmd)
- sw, err := NewSyncWorker(w)
- if err != nil {
- b.Fatal(err)
- }
- b.ReportAllocs()
- b.ResetTimer()
- go func() {
- err := w.Wait()
- if err != nil {
- b.Errorf("error waiting the worker: error %v", err)
- }
- }()
- defer func() {
- err := w.Stop(context.Background())
- if err != nil {
- b.Errorf("error stopping the worker: error %v", err)
- }
- }()
-
- for n := 0; n < b.N; n++ {
- if _, err := sw.Exec(Payload{Body: []byte("hello")}); err != nil {
- b.Fail()
- }
- }
-}
-
-func Benchmark_Pipe_Worker_ExecEcho3(b *testing.B) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- if err != nil {
- b.Fatal(err)
- }
-
- defer func() {
- err = w.Stop(ctx)
- if err != nil {
- b.Errorf("error stopping the WorkerProcess: error %v", err)
- }
- }()
-
- sw, err := NewSyncWorker(w)
- if err != nil {
- b.Fatal(err)
- }
-
- for n := 0; n < b.N; n++ {
- if _, err := sw.Exec(Payload{Body: []byte("hello")}); err != nil {
- b.Fail()
- }
- }
-}
-
-func Benchmark_Pipe_Worker_ExecEchoWithoutContext(b *testing.B) {
- cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd)
- if err != nil {
- b.Fatal(err)
- }
-
- defer func() {
- err = w.Stop(ctx)
- if err != nil {
- b.Errorf("error stopping the WorkerProcess: error %v", err)
- }
- }()
-
- sw, err := NewSyncWorker(w)
- if err != nil {
- b.Fatal(err)
- }
-
- for n := 0; n < b.N; n++ {
- if _, err := sw.Exec(Payload{Body: []byte("hello")}); err != nil {
- b.Fail()
- }
- }
-}