summaryrefslogtreecommitdiff
path: root/pkg/pool/supervisor_test.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-13 13:56:40 +0300
committerValery Piashchynski <[email protected]>2021-01-13 13:56:40 +0300
commit2eed81d8fdbf8ee5134bb3b3f4c11c63cf6d757c (patch)
tree362f0eacdf2373bf208441577c1e69b8337bd71e /pkg/pool/supervisor_test.go
parent581bb5370c89d749b77209b841fec30544c16246 (diff)
Add IdleTTL test
Add removed state to the worker before it being removed
Diffstat (limited to 'pkg/pool/supervisor_test.go')
-rw-r--r--pkg/pool/supervisor_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go
index cb67ebe1..72226bee 100644
--- a/pkg/pool/supervisor_test.go
+++ b/pkg/pool/supervisor_test.go
@@ -112,6 +112,47 @@ func TestSupervisedPool_ExecTTL_TimedOut(t *testing.T) {
assert.NotEqual(t, pid, p.Workers()[0].Pid())
}
+func TestSupervisedPool_Idle(t *testing.T) {
+ var cfgExecTTL = Config{
+ NumWorkers: int64(1),
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ Supervisor: &SupervisorConfig{
+ WatchTick: 1,
+ TTL: 100,
+ IdleTTL: 1,
+ ExecTTL: 100,
+ MaxWorkerMemory: 100,
+ },
+ }
+ ctx := context.Background()
+ p, err := Initialize(
+ ctx,
+ func() *exec.Cmd { return exec.Command("php", "../../tests/sleep.php", "pipes") },
+ pipe.NewPipeFactory(),
+ cfgExecTTL,
+ )
+
+ assert.NoError(t, err)
+ assert.NotNil(t, p)
+ defer p.Destroy(context.Background())
+
+ pid := p.Workers()[0].Pid()
+
+ resp, err := p.ExecWithContext(context.Background(), payload.Payload{
+ Context: []byte(""),
+ Body: []byte("foo"),
+ })
+
+ assert.Nil(t, err)
+ assert.Empty(t, resp.Body)
+ assert.Empty(t, resp.Context)
+
+ time.Sleep(time.Second * 5)
+ // should be new worker with new pid
+ assert.NotEqual(t, pid, p.Workers()[0].Pid())
+}
+
func TestSupervisedPool_ExecTTL_OK(t *testing.T) {
var cfgExecTTL = Config{
NumWorkers: int64(1),