Merge pull request #1511 from euank/fix-oom-tests

oomparser: Fix tests
This commit is contained in:
Tim St. Clair 2016-10-20 18:37:52 -07:00 committed by GitHub
commit 1f00ce6905

View File

@ -18,10 +18,11 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"os" "os"
"reflect"
"strconv" "strconv"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
) )
const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0" const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
@ -32,7 +33,7 @@ const systemLogFile = "systemOomExampleLog.txt"
func createExpectedContainerOomInstance(t *testing.T) *OomInstance { func createExpectedContainerOomInstance(t *testing.T) *OomInstance {
const longForm = "Jan _2 15:04:05 2006" const longForm = "Jan _2 15:04:05 2006"
deathTime, err := time.ParseInLocation(longForm, "Jan 5 15:19:27 2015", time.Local) deathTime, err := time.ParseInLocation(longForm, fmt.Sprintf("Jan 5 15:19:27 %d", time.Now().Year()), time.Local)
if err != nil { if err != nil {
t.Fatalf("could not parse expected time when creating expected container oom instance. Had error %v", err) t.Fatalf("could not parse expected time when creating expected container oom instance. Had error %v", err)
return nil return nil
@ -42,13 +43,13 @@ func createExpectedContainerOomInstance(t *testing.T) *OomInstance {
ProcessName: "memorymonster", ProcessName: "memorymonster",
TimeOfDeath: deathTime, TimeOfDeath: deathTime,
ContainerName: "/mem2", ContainerName: "/mem2",
VictimContainerName: "/mem3", VictimContainerName: "/mem2",
} }
} }
func createExpectedSystemOomInstance(t *testing.T) *OomInstance { func createExpectedSystemOomInstance(t *testing.T) *OomInstance {
const longForm = "Jan _2 15:04:05 2006" const longForm = "Jan _2 15:04:05 2006"
deathTime, err := time.ParseInLocation(longForm, "Jan 28 19:58:45 2015", time.Local) deathTime, err := time.ParseInLocation(longForm, fmt.Sprintf("Jan 28 19:58:45 %d", time.Now().Year()), time.Local)
if err != nil { if err != nil {
t.Fatalf("could not parse expected time when creating expected system oom instance. Had error %v", err) t.Fatalf("could not parse expected time when creating expected system oom instance. Had error %v", err)
return nil return nil
@ -58,7 +59,7 @@ func createExpectedSystemOomInstance(t *testing.T) *OomInstance {
ProcessName: "badsysprogram", ProcessName: "badsysprogram",
TimeOfDeath: deathTime, TimeOfDeath: deathTime,
ContainerName: "/", ContainerName: "/",
VictimContainerName: "/", VictimContainerName: "",
} }
} }
@ -148,10 +149,7 @@ func helpTestStreamOoms(oomCheckInstance *OomInstance, sysFile string, t *testin
select { select {
case oomInstance := <-outStream: case oomInstance := <-outStream:
if reflect.DeepEqual(*oomCheckInstance, *oomInstance) { assert.Equal(t, oomCheckInstance, oomInstance)
t.Errorf("wrong instance returned. Expected %v and got %v",
oomCheckInstance, oomInstance)
}
case <-timeout: case <-timeout:
t.Error( t.Error(
"timeout happened before oomInstance was found in test file") "timeout happened before oomInstance was found in test file")