diff options
author | Valery Piashchynski <[email protected]> | 2020-11-09 15:11:10 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-09 15:11:10 +0300 |
commit | 0874bcb2f6b284a940ba4f3507eb8c4619c27868 (patch) | |
tree | c99d15624cd080cad22b7c8fb7d4714b2dc124fb /static_pool_test.go | |
parent | 9fbe7726dd55cfedda724b7644e1b6bf7c1a6cb4 (diff) | |
parent | f218dcbd7e55d9ad1df8336e2331cdaa62d9ded3 (diff) |
Merge pull request #390 from spiral/feature/switch_to_spiral_errorsv2.0.0-alpha17
Feature/switch to spiral errors
Diffstat (limited to 'static_pool_test.go')
-rwxr-xr-x | static_pool_test.go | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/static_pool_test.go b/static_pool_test.go index f1e3e4e4..8f8a6f56 100755 --- a/static_pool_test.go +++ b/static_pool_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/spiral/errors" "github.com/stretchr/testify/assert" ) @@ -152,52 +153,49 @@ func Test_StaticPool_JobError(t *testing.T) { assert.Nil(t, res.Body) assert.Nil(t, res.Context) - assert.IsType(t, ExecError{}, err) - assert.Equal(t, "hello", err.Error()) + if errors.Is(errors.Exec, err) == false { + t.Fatal("error should be of type errors.Exec") + } + + assert.Contains(t, err.Error(), "exec payload: Exec: hello") } -// TODO temporary commented, figure out later -// func Test_StaticPool_Broken_Replace(t *testing.T) { -// ctx := context.Background() -// p, err := NewPool( -// ctx, -// func() *exec.Cmd { return exec.Command("php", "tests/client.php", "broken", "pipes") }, -// NewPipeFactory(), -// cfg, -// ) -// assert.NoError(t, err) -// assert.NotNil(t, p) -// -// wg := &sync.WaitGroup{} -// wg.Add(1) -// var i int64 -// atomic.StoreInt64(&i, 10) -// -// p.AddListener(func(event interface{}) { -// -// }) -// -// go func() { -// for { -// select { -// case ev := <-p.Events(): -// wev := ev.Payload.(WorkerEvent) -// if _, ok := wev.Payload.([]byte); ok { -// assert.Contains(t, string(wev.Payload.([]byte)), "undefined_function()") -// wg.Done() -// return -// } -// } -// } -// }() -// res, err := p.ExecWithContext(ctx, Payload{Body: []byte("hello")}) -// assert.Error(t, err) -// assert.Nil(t, res.Context) -// assert.Nil(t, res.Body) -// wg.Wait() -// -// p.Destroy(ctx) -// } +func Test_StaticPool_Broken_Replace(t *testing.T) { + ctx := context.Background() + p, err := NewPool( + ctx, + func() *exec.Cmd { return exec.Command("php", "tests/client.php", "broken", "pipes") }, + NewPipeFactory(), + cfg, + ) + assert.NoError(t, err) + assert.NotNil(t, p) + + wg := &sync.WaitGroup{} + wg.Add(1) + + workers := p.Workers() + for i := 0; i < len(workers); i++ { + workers[i].AddListener(func(event interface{}) { + if wev, ok := event.(WorkerEvent); ok { + if wev.Event == EventWorkerLog { + assert.Contains(t, string(wev.Payload.([]byte)), "undefined_function()") + wg.Done() + return + } + } + }) + } + + res, err := p.ExecWithContext(ctx, Payload{Body: []byte("hello")}) + assert.Error(t, err) + assert.Nil(t, res.Context) + assert.Nil(t, res.Body) + + wg.Wait() + + p.Destroy(ctx) +} // func Test_StaticPool_Broken_FromOutside(t *testing.T) { |