summaryrefslogtreecommitdiff
path: root/pool_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-01-28 15:42:17 +0300
committerWolfy-J <[email protected]>2018-01-28 15:42:17 +0300
commitf77a21dc89af9258451fcb7a6d47aa720978a619 (patch)
treefecc1285fcda08aa945f7651454a7689ad246935 /pool_test.go
parenta5a62eeb19e67cbeced09729757cbfdf2cde8821 (diff)
stop by worker
Diffstat (limited to 'pool_test.go')
-rw-r--r--pool_test.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/pool_test.go b/pool_test.go
index 76dc233e..121191ee 100644
--- a/pool_test.go
+++ b/pool_test.go
@@ -188,8 +188,6 @@ func Test_Pool_AllocateTimeout(t *testing.T) {
p.Destroy()
}
-//todo: termiante
-
func Test_Pool_Replace_Worker(t *testing.T) {
p, err := NewPool(
func() *exec.Cmd { return exec.Command("php", "tests/client.php", "pid", "pipes") },
@@ -225,6 +223,41 @@ func Test_Pool_Replace_Worker(t *testing.T) {
}
}
+// identical to replace but controlled on worker side
+func Test_Pool_Stop_Worker(t *testing.T) {
+ p, err := NewPool(
+ func() *exec.Cmd { return exec.Command("php", "tests/client.php", "stop", "pipes") },
+ NewPipeFactory(),
+ Config{
+ NumWorkers: 1,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ )
+ defer p.Destroy()
+
+ assert.NotNil(t, p)
+ assert.NoError(t, err)
+
+ var lastPID string
+ lastPID = strconv.Itoa(*p.Workers()[0].Pid)
+
+ res, err := p.Exec(&Payload{Body: []byte("hello")})
+ assert.Equal(t, lastPID, string(res.Body))
+
+ for i := 0; i < 10; i++ {
+ res, err := p.Exec(&Payload{Body: []byte("hello")})
+
+ assert.NoError(t, err)
+ assert.NotNil(t, res)
+ assert.NotNil(t, res.Body)
+ assert.Nil(t, res.Head)
+
+ assert.NotEqual(t, lastPID, string(res.Body))
+ lastPID = string(res.Body)
+ }
+}
+
func Benchmark_Pool_Allocate(b *testing.B) {
p, _ := NewPool(
func() *exec.Cmd { return exec.Command("php", "tests/client.php", "echo", "pipes") },