diff options
author | Wolfy-J <[email protected]> | 2020-10-26 21:12:46 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2020-10-26 21:12:46 +0300 |
commit | 6d3bd7d47aa9d08847eecfb241298f323aae05ca (patch) | |
tree | ceedc92534ed148de0560e6d32cbc12f0d7bb71c /static_pool_test.go | |
parent | 91cf918b30938129609323ded53e190385e019a6 (diff) |
- lazy load test
Diffstat (limited to 'static_pool_test.go')
-rwxr-xr-x | static_pool_test.go | 44 |
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() |