diff options
-rw-r--r-- | service/rpc/config_test.go | 2 | ||||
-rw-r--r-- | static_pool_test.go | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/service/rpc/config_test.go b/service/rpc/config_test.go index 1db6a4e0..b335be19 100644 --- a/service/rpc/config_test.go +++ b/service/rpc/config_test.go @@ -141,4 +141,4 @@ func Test_Config_Defaults(t *testing.T) { c.InitDefaults() assert.Equal(t, true, c.Enable) assert.Equal(t, "tcp://127.0.0.1:6001", c.Listen) -}
\ No newline at end of file +} diff --git a/static_pool_test.go b/static_pool_test.go index ab8d89e4..036cd092 100644 --- a/static_pool_test.go +++ b/static_pool_test.go @@ -303,6 +303,49 @@ func Test_StaticPool_Stop_Worker(t *testing.T) { } } +// identical to replace but controlled on worker side +func Test_Static_Pool_Destroy_And_Close(t *testing.T) { + p, err := NewPool( + func() *exec.Cmd { return exec.Command("php", "tests/client.php", "delay", "pipes") }, + NewPipeFactory(), + Config{ + NumWorkers: 1, + AllocateTimeout: time.Second, + DestroyTimeout: time.Second, + }, + ) + + assert.NotNil(t, p) + assert.NoError(t, err) + + p.Destroy() + _, err = p.Exec(&Payload{Body: []byte("100")}) + assert.Error(t, err) +} + +// identical to replace but controlled on worker side +func Test_Static_Pool_Destroy_And_Close_While_Wait(t *testing.T) { + p, err := NewPool( + func() *exec.Cmd { return exec.Command("php", "tests/client.php", "delay", "pipes") }, + NewPipeFactory(), + Config{ + NumWorkers: 1, + AllocateTimeout: time.Second, + DestroyTimeout: time.Second, + }, + ) + + assert.NotNil(t, p) + assert.NoError(t, err) + + go p.Exec(&Payload{Body: []byte("100")}) + time.Sleep(time.Millisecond * 10) + + p.Destroy() + _, err = p.Exec(&Payload{Body: []byte("100")}) + assert.Error(t, err) +} + func Benchmark_Pool_Allocate(b *testing.B) { p, _ := NewPool( func() *exec.Cmd { return exec.Command("php", "tests/client.php", "echo", "pipes") }, |