Skip to content

Commit

Permalink
more trying to track down test failures this commit will go away
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenriks committed Aug 9, 2018
1 parent fddcf03 commit ec230db
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions pkg/image/prlimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package image
import (
"bytes"
"os/exec"
"path/filepath"
"testing"
"time"

Expand All @@ -37,10 +36,12 @@ func TestLimits(t *testing.T) {
commandArgs []string
}

memConsumerScript, err := filepath.Abs("../../test/scripts/memory-consumer.sh")
if err != nil {
t.Error("Can't find mamory consumer script")
}
/*
memConsumerScript, err := filepath.Abs("../../test/scripts/memory-consumer.sh")
if err != nil {
t.Error("Can't find mamory consumer script")
}
*/

tests := []struct {
name string
Expand All @@ -57,22 +58,23 @@ func TestLimits(t *testing.T) {
args: args{cpuLimitFunction(1), 2 * time.Second, "dd", []string{"if=/dev/zero", "of=/dev/null", "count=1000000000"}},
errorMessage: "signal: killed",
},

{
name: "normal execution with memory limit",
args: args{memoryLimitFunction(twentyFiveMeg), 10 * time.Second, memConsumerScript, []string{"512"}},
errorMessage: "",
},
{
name: "should get killed by memory limit",
args: args{memoryLimitFunction(twentyFiveMeg), 10 * time.Second, memConsumerScript, []string{"2048"}},
errorMessage: "exit status 2",
},
{
name: "should get killed by test",
args: args{func(int) {}, 4 * time.Second, memConsumerScript, []string{"2048"}},
errorMessage: killedByTestError,
},
/*
{
name: "normal execution with memory limit",
args: args{memoryLimitFunction(twentyFiveMeg), 10 * time.Second, memConsumerScript, []string{"512"}},
errorMessage: "",
},
{
name: "should get killed by memory limit",
args: args{memoryLimitFunction(twentyFiveMeg), 10 * time.Second, memConsumerScript, []string{"2048"}},
errorMessage: "exit status 2",
},
{
name: "should get killed by test",
args: args{func(int) {}, 4 * time.Second, memConsumerScript, []string{"2048"}},
errorMessage: killedByTestError,
},
*/
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -116,9 +118,10 @@ func executeComand(limitFunction func(int), maxTime time.Duration, command strin

timeout := time.After(maxTime)

defer cmd.Process.Kill()

select {
case <-timeout:
cmd.Process.Kill()
return nil, errors.New(killedByTestError)
case err := <-done:
return buf.Bytes(), err
Expand Down

0 comments on commit ec230db

Please sign in to comment.