summaryrefslogtreecommitdiff
path: root/pkg/transport/pipe
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-02-03 17:31:17 +0300
committerValery Piashchynski <[email protected]>2021-02-03 17:31:17 +0300
commit8eda5dc6f0f7e05d7b3d62e1861af05b49a2574a (patch)
treefae66ad49d2a4624a7caf45a5bf07d53e5c7d26f /pkg/transport/pipe
parent20a1a5d2eb26090e0eef0e6772330ee2a52526fa (diff)
Fix memory leak in the Worker.go
Diffstat (limited to 'pkg/transport/pipe')
-rw-r--r--pkg/transport/pipe/pipe_factory_spawn_test.go14
-rwxr-xr-xpkg/transport/pipe/pipe_factory_test.go16
2 files changed, 26 insertions, 4 deletions
diff --git a/pkg/transport/pipe/pipe_factory_spawn_test.go b/pkg/transport/pipe/pipe_factory_spawn_test.go
index e247324c..663b3dd5 100644
--- a/pkg/transport/pipe/pipe_factory_spawn_test.go
+++ b/pkg/transport/pipe/pipe_factory_spawn_test.go
@@ -106,11 +106,21 @@ func Test_Pipe_PipeError4(t *testing.T) {
func Test_Pipe_Failboot2(t *testing.T) {
cmd := exec.Command("php", "../../../tests/failboot.php")
- w, err := NewPipeFactory().SpawnWorker(cmd)
+ finish := make(chan struct{}, 1)
+ listener := func(event interface{}) {
+ if ev, ok := event.(events.WorkerEvent); ok {
+ if ev.Event == events.EventWorkerStderr {
+ if strings.Contains(string(ev.Payload.([]byte)), "failboot") {
+ finish <- struct{}{}
+ }
+ }
+ }
+ }
+ w, err := NewPipeFactory().SpawnWorker(cmd, listener)
assert.Nil(t, w)
assert.Error(t, err)
- assert.Contains(t, err.Error(), "failboot")
+ <-finish
}
func Test_Pipe_Invalid2(t *testing.T) {
diff --git a/pkg/transport/pipe/pipe_factory_test.go b/pkg/transport/pipe/pipe_factory_test.go
index b23af19f..6045dd91 100755
--- a/pkg/transport/pipe/pipe_factory_test.go
+++ b/pkg/transport/pipe/pipe_factory_test.go
@@ -117,11 +117,23 @@ func Test_Pipe_PipeError2(t *testing.T) {
func Test_Pipe_Failboot(t *testing.T) {
cmd := exec.Command("php", "../../../tests/failboot.php")
ctx := context.Background()
- w, err := NewPipeFactory().SpawnWorkerWithTimeout(ctx, cmd)
+
+ finish := make(chan struct{}, 1)
+ listener := func(event interface{}) {
+ if ev, ok := event.(events.WorkerEvent); ok {
+ if ev.Event == events.EventWorkerStderr {
+ if strings.Contains(string(ev.Payload.([]byte)), "failboot") {
+ finish <- struct{}{}
+ }
+ }
+ }
+ }
+
+ w, err := NewPipeFactory().SpawnWorkerWithTimeout(ctx, cmd, listener)
assert.Nil(t, w)
assert.Error(t, err)
- assert.Contains(t, err.Error(), "failboot")
+ <-finish
}
func Test_Pipe_Invalid(t *testing.T) {