From 6d3bd7d47aa9d08847eecfb241298f323aae05ca Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 26 Oct 2020 21:12:46 +0300 Subject: - lazy load test --- static_pool_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'static_pool_test.go') 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() -- cgit v1.2.3