Skip to content

Commit

Permalink
fix: process resources are not released (#66)
Browse files Browse the repository at this point in the history
Fixed #60
  • Loading branch information
k3rn31 committed Jul 27, 2022
1 parent 34fbfa9 commit 4fc2094
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions mutator/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ package mutator

import (
"context"
"github.com/k3rn31/gremlins/coverage"
"github.com/k3rn31/gremlins/log"
"github.com/k3rn31/gremlins/mutant"
"github.com/k3rn31/gremlins/mutator/internal"
"github.com/k3rn31/gremlins/mutator/workdir"
"github.com/k3rn31/gremlins/report"
"go/ast"
"go/parser"
"go/token"
Expand All @@ -34,6 +28,13 @@ import (
"path/filepath"
"strings"
"time"

"github.com/k3rn31/gremlins/coverage"
"github.com/k3rn31/gremlins/log"
"github.com/k3rn31/gremlins/mutant"
"github.com/k3rn31/gremlins/mutator/internal"
"github.com/k3rn31/gremlins/mutator/workdir"
"github.com/k3rn31/gremlins/report"
)

// Mutator is the "engine" that performs the mutation testing.
Expand Down Expand Up @@ -241,7 +242,9 @@ func (mu *Mutator) runTests() mutant.Status {
defer cancel()
cmd := mu.execContext(ctx, "go", mu.getTestArgs()...)

err := cmd.Run()
rel, err := run(cmd)
defer rel()

if ctx.Err() == context.DeadlineExceeded {
return mutant.TimedOut
}
Expand All @@ -254,6 +257,20 @@ func (mu *Mutator) runTests() mutant.Status {
return mutant.Lived
}

func run(cmd *exec.Cmd) (func(), error) {
if err := cmd.Run(); err != nil {

return func() {}, err
}

return func() {
err := cmd.Process.Release()
if err != nil {
_ = cmd.Process.Kill()
}
}, nil
}

func (mu *Mutator) getTestArgs() []string {
args := []string{"test"}
if mu.buildTags != "" {
Expand Down

0 comments on commit 4fc2094

Please # to comment.