summaryrefslogtreecommitdiff
path: root/static_pool_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-26 21:12:46 +0300
committerWolfy-J <[email protected]>2020-10-26 21:12:46 +0300
commit6d3bd7d47aa9d08847eecfb241298f323aae05ca (patch)
treeceedc92534ed148de0560e6d32cbc12f0d7bb71c /static_pool_test.go
parent91cf918b30938129609323ded53e190385e019a6 (diff)
- lazy load test
Diffstat (limited to 'static_pool_test.go')
-rwxr-xr-xstatic_pool_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/static_pool_test.go b/static_pool_test.go
index ec80e92a..c9a43f69 100755
--- a/static_pool_test.go
+++ b/static_pool_test.go
@@ -301,6 +301,50 @@ func Test_StaticPool_Replace_Worker(t *testing.T) {
}
}
+func Test_StaticPool_Debug_Worker(t *testing.T) {
+ ctx := context.Background()
+ p, err := NewPool(
+ ctx,
+ func() *exec.Cmd { return exec.Command("php", "tests/client.php", "pid", "pipes") },
+ NewPipeFactory(),
+ Config{
+ Deferred: true,
+ NumWorkers: 1,
+ MaxJobs: 1,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ )
+ assert.NoError(t, err)
+ defer p.Destroy(ctx)
+
+ assert.NotNil(t, p)
+
+ assert.Len(t, p.Workers(), 0)
+
+ var lastPID string
+ res, _ := p.Exec(Payload{Body: []byte("hello")})
+
+ assert.Len(t, p.Workers(), 1)
+
+ lastPID = strconv.Itoa(int(p.Workers()[0].Pid()))
+ res, _ = p.Exec(Payload{Body: []byte("hello")})
+ assert.NotEqual(t, lastPID, string(res.Body))
+
+ for i := 0; i < 10; i++ {
+ lastPID = strconv.Itoa(int(p.Workers()[0].Pid()))
+ 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) {
ctx := context.Background()