diff options
Diffstat (limited to 'pkg/pipe/pipe_factory_test.go')
-rwxr-xr-x | pkg/pipe/pipe_factory_test.go | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/pkg/pipe/pipe_factory_test.go b/pkg/pipe/pipe_factory_test.go index 7045b785..40797747 100755 --- a/pkg/pipe/pipe_factory_test.go +++ b/pkg/pipe/pipe_factory_test.go @@ -11,7 +11,8 @@ import ( "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/interfaces/events" "github.com/spiral/roadrunner/v2/internal" - "github.com/spiral/roadrunner/v2/pkg/worker" + "github.com/spiral/roadrunner/v2/pkg/payload" + workerImpl "github.com/spiral/roadrunner/v2/pkg/worker" "github.com/stretchr/testify/assert" ) @@ -146,12 +147,12 @@ func Test_Pipe_Echo(t *testing.T) { } }() - sw, err := worker.From(w) + sw, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - res, err := sw.Exec(internal.Payload{Body: []byte("hello")}) + res, err := sw.Exec(payload.Payload{Body: []byte("hello")}) assert.NoError(t, err) assert.NotNil(t, res) @@ -174,12 +175,12 @@ func Test_Pipe_Broken(t *testing.T) { assert.Error(t, err) }() - sw, err := worker.From(w) + sw, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - res, err := sw.Exec(internal.Payload{Body: []byte("hello")}) + res, err := sw.Exec(payload.Payload{Body: []byte("hello")}) assert.Error(t, err) assert.Nil(t, res.Body) @@ -208,7 +209,7 @@ 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 := worker.From(w) + sw, err := workerImpl.From(w) if err != nil { b.Fatal(err) } @@ -228,7 +229,7 @@ func Benchmark_Pipe_Worker_ExecEcho(b *testing.B) { }() for n := 0; n < b.N; n++ { - if _, err := sw.Exec(internal.Payload{Body: []byte("hello")}); err != nil { + if _, err := sw.Exec(payload.Payload{Body: []byte("hello")}); err != nil { b.Fail() } } @@ -249,13 +250,13 @@ func Benchmark_Pipe_Worker_ExecEcho3(b *testing.B) { } }() - sw, err := worker.From(w) + sw, err := workerImpl.From(w) if err != nil { b.Fatal(err) } for n := 0; n < b.N; n++ { - if _, err := sw.Exec(internal.Payload{Body: []byte("hello")}); err != nil { + if _, err := sw.Exec(payload.Payload{Body: []byte("hello")}); err != nil { b.Fail() } } @@ -276,13 +277,13 @@ func Benchmark_Pipe_Worker_ExecEchoWithoutContext(b *testing.B) { } }() - sw, err := worker.From(w) + sw, err := workerImpl.From(w) if err != nil { b.Fatal(err) } for n := 0; n < b.N; n++ { - if _, err := sw.Exec(internal.Payload{Body: []byte("hello")}); err != nil { + if _, err := sw.Exec(payload.Payload{Body: []byte("hello")}); err != nil { b.Fail() } } @@ -297,7 +298,7 @@ func Test_Echo(t *testing.T) { t.Fatal(err) } - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } @@ -311,7 +312,7 @@ func Test_Echo(t *testing.T) { } }() - res, err := syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + res, err := syncWorker.Exec(payload.Payload{Body: []byte("hello")}) assert.Nil(t, err) assert.NotNil(t, res) @@ -327,7 +328,7 @@ func Test_BadPayload(t *testing.T) { w, _ := NewPipeFactory().SpawnWorkerWithContext(ctx, cmd) - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } @@ -342,7 +343,7 @@ func Test_BadPayload(t *testing.T) { } }() - res, err := syncWorker.Exec(internal.Payload{}) + res, err := syncWorker.Exec(payload.Payload{}) assert.Error(t, err) assert.Nil(t, res.Body) @@ -386,12 +387,12 @@ func Test_Echo_Slow(t *testing.T) { } }() - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - res, err := syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + res, err := syncWorker.Exec(payload.Payload{Body: []byte("hello")}) assert.Nil(t, err) assert.NotNil(t, res) @@ -420,12 +421,12 @@ func Test_Broken(t *testing.T) { } }) - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - res, err := syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + res, err := syncWorker.Exec(payload.Payload{Body: []byte("hello")}) assert.NotNil(t, err) assert.Nil(t, res.Body) assert.Nil(t, res.Context) @@ -455,12 +456,12 @@ func Test_Error(t *testing.T) { } }() - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - res, err := syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + res, err := syncWorker.Exec(payload.Payload{Body: []byte("hello")}) assert.NotNil(t, err) assert.Nil(t, res.Body) assert.Nil(t, res.Context) @@ -468,7 +469,7 @@ func Test_Error(t *testing.T) { if errors.Is(errors.ErrSoftJob, err) == false { t.Fatal("error should be of type errors.ErrSoftJob") } - assert.Contains(t, err.Error(), "exec payload: SoftJobError: hello") + assert.Contains(t, err.Error(), "hello") } func Test_NumExecs(t *testing.T) { @@ -486,24 +487,24 @@ func Test_NumExecs(t *testing.T) { } }() - syncWorker, err := worker.From(w) + syncWorker, err := workerImpl.From(w) if err != nil { t.Fatal(err) } - _, err = syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + _, err = syncWorker.Exec(payload.Payload{Body: []byte("hello")}) if err != nil { t.Errorf("fail to execute payload: error %v", err) } assert.Equal(t, int64(1), w.State().NumExecs()) - _, err = syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + _, err = syncWorker.Exec(payload.Payload{Body: []byte("hello")}) if err != nil { t.Errorf("fail to execute payload: error %v", err) } assert.Equal(t, int64(2), w.State().NumExecs()) - _, err = syncWorker.Exec(internal.Payload{Body: []byte("hello")}) + _, err = syncWorker.Exec(payload.Payload{Body: []byte("hello")}) if err != nil { t.Errorf("fail to execute payload: error %v", err) } |