diff options
author | Valery Piashchynski <[email protected]> | 2021-06-26 01:56:23 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-26 01:56:23 +0300 |
commit | f87153d8b89c1b92040fad53b529c740a8f972fc (patch) | |
tree | a84bc14b225cdb9e00b3c1ab9553f247cecf731a /pkg/pool/supervisor_test.go | |
parent | 7c0b63a9d0cee75e8bdedd2dcd0c20139f3ffd3f (diff) |
- Add more tests
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg/pool/supervisor_test.go')
-rw-r--r-- | pkg/pool/supervisor_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go index f371b925..513d369f 100644 --- a/pkg/pool/supervisor_test.go +++ b/pkg/pool/supervisor_test.go @@ -170,6 +170,48 @@ func TestSupervisedPool_Idle(t *testing.T) { p.Destroy(context.Background()) } +func TestSupervisedPool_IdleTTL_StateAfterTimeout(t *testing.T) { + var cfgExecTTL = Config{ + NumWorkers: uint64(1), + AllocateTimeout: time.Second, + DestroyTimeout: time.Second, + Supervisor: &SupervisorConfig{ + WatchTick: 1 * time.Second, + TTL: 1 * time.Second, + IdleTTL: 1 * time.Second, + MaxWorkerMemory: 100, + }, + } + ctx := context.Background() + p, err := Initialize( + ctx, + func() *exec.Cmd { return exec.Command("php", "../../tests/exec_ttl.php", "pipes") }, + pipe.NewPipeFactory(), + cfgExecTTL, + ) + + assert.NoError(t, err) + assert.NotNil(t, p) + defer p.Destroy(context.Background()) + + pid := p.Workers()[0].Pid() + + time.Sleep(time.Millisecond * 100) + resp, err := p.Exec(payload.Payload{ + Context: []byte(""), + Body: []byte("foo"), + }) + + assert.NoError(t, err) + assert.Empty(t, resp.Body) + assert.Empty(t, resp.Context) + + time.Sleep(time.Second * 2) + // should be destroyed, state should be Ready, not Invalid + assert.NotEqual(t, pid, p.Workers()[0].Pid()) + assert.Equal(t, int64(1), p.Workers()[0].State().Value()) +} + func TestSupervisedPool_ExecTTL_OK(t *testing.T) { var cfgExecTTL = Config{ NumWorkers: uint64(1), |