summaryrefslogtreecommitdiff
path: root/sync_worker_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-25 15:55:51 +0300
committerWolfy-J <[email protected]>2020-10-25 15:55:51 +0300
commitba5c562f9038ba434e655fb82c44597fcccaff16 (patch)
treeff112b9dcffda63bc40094a57d0df61622368445 /sync_worker_test.go
parent3bdf7d02d83d1ff4726f3fbb01a45d016f39abec (diff)
- massive update in roadrunner 2.0 abstractions
Diffstat (limited to 'sync_worker_test.go')
-rw-r--r--sync_worker_test.go62
1 files changed, 32 insertions, 30 deletions
diff --git a/sync_worker_test.go b/sync_worker_test.go
index f4868009..ad1513d7 100644
--- a/sync_worker_test.go
+++ b/sync_worker_test.go
@@ -2,13 +2,10 @@ package roadrunner
import (
"context"
- "errors"
+ "github.com/stretchr/testify/assert"
"os/exec"
"sync"
"testing"
- "time"
-
- "github.com/stretchr/testify/assert"
)
func Test_Echo(t *testing.T) {
@@ -34,7 +31,7 @@ func Test_Echo(t *testing.T) {
}
}()
- res, err := syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ res, err := syncWorker.Exec(Payload{Body: []byte("hello")})
assert.Nil(t, err)
assert.NotNil(t, res)
@@ -65,7 +62,7 @@ func Test_BadPayload(t *testing.T) {
}
}()
- res, err := syncWorker.ExecWithContext(ctx, EmptyPayload)
+ res, err := syncWorker.Exec(EmptyPayload)
assert.Error(t, err)
assert.Nil(t, res.Body)
@@ -84,7 +81,6 @@ func Test_NotStarted_String(t *testing.T) {
}
func Test_NotStarted_Exec(t *testing.T) {
- ctx := context.Background()
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
w, _ := InitBaseWorker(cmd)
@@ -94,7 +90,7 @@ func Test_NotStarted_Exec(t *testing.T) {
t.Fatal(err)
}
- res, err := syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ res, err := syncWorker.Exec(Payload{Body: []byte("hello")})
assert.Error(t, err)
assert.Nil(t, res.Body)
@@ -143,7 +139,7 @@ func Test_Echo_Slow(t *testing.T) {
t.Fatal(err)
}
- res, err := syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ res, err := syncWorker.Exec(Payload{Body: []byte("hello")})
assert.Nil(t, err)
assert.NotNil(t, res)
@@ -164,28 +160,34 @@ func Test_Broken(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
- go func() {
- assert.NotNil(t, w)
- tt := time.NewTimer(time.Second * 10)
- defer wg.Done()
- for {
- select {
- case ev := <-w.Events():
- assert.Contains(t, string(ev.Payload.([]byte)), "undefined_function()")
- return
- case <-tt.C:
- assert.Error(t, errors.New("no events from worker"))
- return
- }
- }
- }()
+
+ w.AddListener(func(event interface{}) {
+ assert.Contains(t, string(event.(WorkerEvent).Payload.([]byte)), "undefined_function()")
+ wg.Done()
+ })
+
+ //go func() {
+ // assert.NotNil(t, w)
+ // tt := time.NewTimer(time.Second * 10)
+ // defer wg.Done()
+ // for {
+ // select {
+ // case ev := <-w.Events():
+ // assert.Contains(t, string(ev.Payload.([]byte)), "undefined_function()")
+ // return
+ // case <-tt.C:
+ // assert.Error(t, errors.New("no events from worker"))
+ // return
+ // }
+ // }
+ //}()
syncWorker, err := NewSyncWorker(w)
if err != nil {
t.Fatal(err)
}
- res, err := syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ res, err := syncWorker.Exec(Payload{Body: []byte("hello")})
assert.NotNil(t, err)
assert.Nil(t, res.Body)
assert.Nil(t, res.Context)
@@ -215,12 +217,12 @@ func Test_Error(t *testing.T) {
t.Fatal(err)
}
- res, err := syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ res, err := syncWorker.Exec(Payload{Body: []byte("hello")})
assert.NotNil(t, err)
assert.Nil(t, res.Body)
assert.Nil(t, res.Context)
- assert.IsType(t, TaskError{}, err)
+ assert.IsType(t, JobError{}, err)
assert.Equal(t, "hello", err.Error())
}
@@ -244,19 +246,19 @@ func Test_NumExecs(t *testing.T) {
t.Fatal(err)
}
- _, err = syncWorker.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ _, err = syncWorker.Exec(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.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ _, err = syncWorker.Exec(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.ExecWithContext(ctx, Payload{Body: []byte("hello")})
+ _, err = syncWorker.Exec(Payload{Body: []byte("hello")})
if err != nil {
t.Errorf("fail to execute payload: error %v", err)
}