diff options
author | Valery Piashchynski <[email protected]> | 2021-02-24 14:16:59 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-24 14:16:59 +0300 |
commit | b3cb0cd2428f1bfdd959ea8f3461e2992b6acdb2 (patch) | |
tree | 0d226eb8ad9730ede1f7cd80b5f7b44d1fb23b0a /pkg/pool/supervisor_test.go | |
parent | 3c5a85bf8a0d1c8b8f8f71c215f75b338c4e7510 (diff) | |
parent | caea9cb452fda97a9496bc33190c95fbc27e54c3 (diff) |
Merge pull request #551 from spiral/rc.4-releasev2.0.0-RC.4
âš¡ release(RC.4): Release RC.4
Diffstat (limited to 'pkg/pool/supervisor_test.go')
-rw-r--r-- | pkg/pool/supervisor_test.go | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go index 85af4672..d7e97fdd 100644 --- a/pkg/pool/supervisor_test.go +++ b/pkg/pool/supervisor_test.go @@ -9,7 +9,6 @@ import ( "github.com/spiral/roadrunner/v2/pkg/events" "github.com/spiral/roadrunner/v2/pkg/payload" "github.com/spiral/roadrunner/v2/pkg/transport/pipe" - "github.com/spiral/roadrunner/v2/tools" "github.com/stretchr/testify/assert" ) @@ -37,28 +36,8 @@ func TestSupervisedPool_Exec(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, p) - stopCh := make(chan struct{}) - defer p.Destroy(context.Background()) - go func() { - for { - select { - case <-stopCh: - return - default: - workers := p.Workers() - if len(workers) > 0 { - s, err := tools.WorkerProcessState(workers[0]) - assert.NoError(t, err) - assert.NotNil(t, s) - // since this is soft limit, double max memory limit watch - if (s.MemoryUsage / MB) > cfgSupervised.Supervisor.MaxWorkerMemory*2 { - assert.Fail(t, "max memory reached, worker still alive") - } - } - } - } - }() + pidBefore := p.Workers()[0].Pid() for i := 0; i < 100; i++ { time.Sleep(time.Millisecond * 100) @@ -69,7 +48,9 @@ func TestSupervisedPool_Exec(t *testing.T) { assert.NoError(t, err) } - stopCh <- struct{}{} + assert.NotEqual(t, pidBefore, p.Workers()[0].Pid()) + + p.Destroy(context.Background()) } func TestSupervisedPool_ExecTTL_TimedOut(t *testing.T) { @@ -99,7 +80,7 @@ func TestSupervisedPool_ExecTTL_TimedOut(t *testing.T) { pid := p.Workers()[0].Pid() - resp, err := p.ExecWithContext(context.Background(), payload.Payload{ + resp, err := p.execWithTTL(context.Background(), payload.Payload{ Context: []byte(""), Body: []byte("foo"), }) @@ -129,7 +110,7 @@ func TestSupervisedPool_Idle(t *testing.T) { ctx := context.Background() p, err := Initialize( ctx, - func() *exec.Cmd { return exec.Command("php", "../../tests/sleep.php", "pipes") }, + func() *exec.Cmd { return exec.Command("php", "../../tests/idle.php", "pipes") }, pipe.NewPipeFactory(), cfgExecTTL, ) @@ -139,7 +120,7 @@ func TestSupervisedPool_Idle(t *testing.T) { pid := p.Workers()[0].Pid() - resp, err := p.ExecWithContext(context.Background(), payload.Payload{ + resp, err := p.execWithTTL(context.Background(), payload.Payload{ Context: []byte(""), Body: []byte("foo"), }) @@ -149,6 +130,13 @@ func TestSupervisedPool_Idle(t *testing.T) { assert.Empty(t, resp.Context) time.Sleep(time.Second * 5) + + // worker should be marked as invalid and reallocated + _, err = p.execWithTTL(context.Background(), payload.Payload{ + Context: []byte(""), + Body: []byte("foo"), + }) + assert.NoError(t, err) // should be new worker with new pid assert.NotEqual(t, pid, p.Workers()[0].Pid()) p.Destroy(context.Background()) @@ -170,7 +158,7 @@ func TestSupervisedPool_ExecTTL_OK(t *testing.T) { ctx := context.Background() p, err := Initialize( ctx, - func() *exec.Cmd { return exec.Command("php", "../../tests/sleep.php", "pipes") }, + func() *exec.Cmd { return exec.Command("php", "../../tests/exec_ttl.php", "pipes") }, pipe.NewPipeFactory(), cfgExecTTL, ) |