diff options
author | Valery Piashchynski <[email protected]> | 2021-01-24 21:02:11 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-01-24 21:02:11 +0300 |
commit | b18a3578b6d299aac5dfcc016c2a3a0f6905aa0d (patch) | |
tree | 2b03c2e50c9b3d371be7d6483146a74c61fb80b0 | |
parent | 74c8e65948b8eec3a71fee723b107f4eb03973d9 (diff) |
Fix TestSupervisedPool_MaxMemoryReached test
-rw-r--r-- | pkg/pool/supervisor_test.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go index a058bd36..73ab4927 100644 --- a/pkg/pool/supervisor_test.go +++ b/pkg/pool/supervisor_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "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" @@ -209,6 +210,15 @@ func TestSupervisedPool_MaxMemoryReached(t *testing.T) { }, } + block := make(chan struct{}, 1) + listener := func(event interface{}) { + if ev, ok := event.(events.PoolEvent); ok { + if ev.Event == events.EventMaxMemory { + block <- struct{}{} + } + } + } + // constructed // max memory // constructed @@ -218,15 +228,12 @@ func TestSupervisedPool_MaxMemoryReached(t *testing.T) { func() *exec.Cmd { return exec.Command("php", "../../tests/memleak.php", "pipes") }, pipe.NewPipeFactory(), cfgExecTTL, + AddListeners(listener), ) 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"), @@ -236,6 +243,6 @@ func TestSupervisedPool_MaxMemoryReached(t *testing.T) { assert.Empty(t, resp.Body) assert.Empty(t, resp.Context) - time.Sleep(time.Second * 5) - assert.NotEqual(t, pid, p.Workers()[0].Pid()) + <-block + p.Destroy(context.Background()) } |