summaryrefslogtreecommitdiff
path: root/static_pool_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-05 23:17:14 +0300
committerWolfy-J <[email protected]>2018-06-05 23:17:14 +0300
commite594c7070aad609c4caeda760671aca00e638561 (patch)
treeb7ecb76ceeba88e03635c238a67f237452c20524 /static_pool_test.go
parent6adaf713b47c9a3ab3a516e21d2d4ecf7f2075d6 (diff)
fixing controlled descruction
Diffstat (limited to 'static_pool_test.go')
-rw-r--r--static_pool_test.go137
1 files changed, 70 insertions, 67 deletions
diff --git a/static_pool_test.go b/static_pool_test.go
index 7e2315d7..5fe7e062 100644
--- a/static_pool_test.go
+++ b/static_pool_test.go
@@ -187,6 +187,9 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) {
p.Observe(func(e int, ctx interface{}) {
if err, ok := ctx.(error); ok {
assert.Contains(t, err.Error(), "exit status 1")
+ }
+
+ if e == EventWorkerCreate {
close(destructed)
}
})
@@ -200,73 +203,73 @@ func Test_StaticPool_Broken_FromOutside(t *testing.T) {
}
}
-//
-//func Test_StaticPool_AllocateTimeout(t *testing.T) {
-// p, err := NewPool(
-// func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "delay", "pipes") },
-// NewPipeFactory(),
-// Config{
-// NumWorkers: 1,
-// AllocateTimeout: time.Millisecond * 50,
-// DestroyTimeout: time.Second,
-// },
-// )
-//
-// assert.NotNil(t, p)
-// assert.NoError(t, err)
-//
-// done := make(chan interface{})
-// go func() {
-// _, err := p.Exec(&Payload{Body: []byte("100")})
-// assert.NoError(t, err)
-// close(done)
-// }()
-//
-// // to ensure that worker is already busy
-// time.Sleep(time.Millisecond * 10)
-//
-// _, err = p.Exec(&Payload{Body: []byte("10")})
-// assert.Error(t, err)
-// assert.Contains(t, err.Error(), "worker timeout")
-//
-// <-done
-// p.Destroy()
-//}
-//
-//func Test_StaticPool_Replace_Worker(t *testing.T) {
-// p, err := NewPool(
-// func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "pid", "pipes") },
-// NewPipeFactory(),
-// Config{
-// NumWorkers: 1,
-// MaxExecutions: 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.Context)
-//
-// assert.NotEqual(t, lastPID, string(res.Body))
-// lastPID = string(res.Body)
-// }
-//}
+
+func Test_StaticPool_AllocateTimeout(t *testing.T) {
+ p, err := NewPool(
+ func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "delay", "pipes") },
+ NewPipeFactory(),
+ Config{
+ NumWorkers: 1,
+ AllocateTimeout: time.Millisecond * 50,
+ DestroyTimeout: time.Second,
+ },
+ )
+
+ assert.NotNil(t, p)
+ assert.NoError(t, err)
+
+ done := make(chan interface{})
+ go func() {
+ _, err := p.Exec(&Payload{Body: []byte("100")})
+ assert.NoError(t, err)
+ close(done)
+ }()
+
+ // to ensure that worker is already busy
+ time.Sleep(time.Millisecond * 10)
+
+ _, err = p.Exec(&Payload{Body: []byte("10")})
+ assert.Error(t, err)
+ assert.Contains(t, err.Error(), "worker timeout")
+
+ <-done
+ p.Destroy()
+}
+
+func Test_StaticPool_Replace_Worker(t *testing.T) {
+ p, err := NewPool(
+ func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "pid", "pipes") },
+ NewPipeFactory(),
+ Config{
+ NumWorkers: 1,
+ MaxExecutions: 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.Context)
+
+ assert.NotEqual(t, lastPID, string(res.Body))
+ lastPID = string(res.Body)
+ }
+}
// identical to replace but controlled on worker side
func Test_StaticPool_Stop_Worker(t *testing.T) {