diff options
author | Wolfy-J <[email protected]> | 2019-12-23 14:43:47 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-12-23 14:43:47 +0300 |
commit | c7b0a4a81827284f7565c56aa476eea34fb6382f (patch) | |
tree | ee30e93169c37fb058fbe55af6b3f954eabd9646 /static_pool_test.go | |
parent | 7f694966730f6dac09d0d0ea3bf51276b8e4dfe4 (diff) |
- test fixes
Diffstat (limited to 'static_pool_test.go')
-rw-r--r-- | static_pool_test.go | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/static_pool_test.go b/static_pool_test.go index a7e71fdb..fd2827cc 100644 --- a/static_pool_test.go +++ b/static_pool_test.go @@ -6,6 +6,7 @@ import ( "os/exec" "runtime" "strconv" + "strings" "sync" "testing" "time" @@ -23,12 +24,13 @@ func Test_NewPool(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) + assert.Equal(t, cfg, p.Config()) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) } func Test_StaticPool_Invalid(t *testing.T) { @@ -62,10 +64,11 @@ func Test_StaticPool_Echo(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) + defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) res, err := p.Exec(&Payload{Body: []byte("hello")}) @@ -83,10 +86,11 @@ func Test_StaticPool_Echo_NilContext(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) + defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) res, err := p.Exec(&Payload{Body: []byte("hello"), Context: nil}) @@ -104,10 +108,11 @@ func Test_StaticPool_Echo_Context(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) + defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) res, err := p.Exec(&Payload{Body: []byte("hello"), Context: []byte("world")}) @@ -125,10 +130,10 @@ func Test_StaticPool_JobError(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) res, err := p.Exec(&Payload{Body: []byte("hello")}) @@ -145,14 +150,17 @@ func Test_StaticPool_Broken_Replace(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) + done := make(chan interface{}) p.Listen(func(e int, ctx interface{}) { if err, ok := ctx.(error); ok { - assert.Contains(t, err.Error(), "undefined_function()") + if strings.Contains(err.Error(), "undefined_function()") { + close(done) + } } }) @@ -160,6 +168,8 @@ func Test_StaticPool_Broken_Replace(t *testing.T) { assert.Error(t, err) assert.Nil(t, res) + + <-done } func Test_StaticPool_Broken_FromOutside(t *testing.T) { @@ -168,10 +178,10 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) { NewPipeFactory(), cfg, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) res, err := p.Exec(&Payload{Body: []byte("hello")}) @@ -191,9 +201,11 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) { }) // killing random worker and expecting pool to replace it - p.muw.Lock() - p.workers[0].cmd.Process.Kill() - p.muw.Unlock() + err = p.Workers()[0].cmd.Process.Kill() + if err != nil { + t.Errorf("error killing the process: error %v", err) + } + <-destructed for _, w := range p.Workers() { @@ -244,10 +256,10 @@ func Test_StaticPool_Replace_Worker(t *testing.T) { DestroyTimeout: time.Second, }, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) var lastPID string lastPID = strconv.Itoa(*p.Workers()[0].Pid) @@ -279,10 +291,10 @@ func Test_StaticPool_Stop_Worker(t *testing.T) { DestroyTimeout: time.Second, }, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) var lastPID string lastPID = strconv.Itoa(*p.Workers()[0].Pid) @@ -338,7 +350,13 @@ func Test_Static_Pool_Destroy_And_Close_While_Wait(t *testing.T) { assert.NotNil(t, p) assert.NoError(t, err) - go p.Exec(&Payload{Body: []byte("100")}) + go func() { + _, err := p.Exec(&Payload{Body: []byte("100")}) + if err != nil { + t.Errorf("error executing payload: error %v", err) + } + + }() time.Sleep(time.Millisecond * 10) p.Destroy() @@ -357,10 +375,10 @@ func Test_Static_Pool_Handle_Dead(t *testing.T) { DestroyTimeout: time.Second, }, ) + assert.NoError(t, err) defer p.Destroy() assert.NotNil(t, p) - assert.NoError(t, err) for _, w := range p.workers { w.state.value = StateErrored |