@@ -23,23 +23,33 @@ import (
23
23
"github.com/stretchr/testify/assert"
24
24
)
25
25
26
- const startLine = "ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
27
- const endLine = "Killed process 19667 (evil-program2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
28
- const containerLine = "Task in /mem2 killed as a result of limit of /mem3"
26
+ const (
27
+ startLine = "ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
28
+ endLine = "Killed process 19667 (evil-program2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
29
+ legacyContainerLine = "Task in /mem2 killed as a result of limit of /mem3"
30
+ containerLine = "oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=ef807430361e6e82b45db92e2e9b6fbec98f419b12c591e655c1a725565e73a8,mems_allowed=0,oom_memcg=/kubepods/burstable/podfbdfe8e3-1c87-4ff2-907 c-b2ec8e25d012,task_memcg=/kubepods/burstable/podfbdfe8e3-1c87-4ff2-907c-b2ec8e25d012/ef807430361e6e82b45db92e2e9b6fbec98f419b12c591e655c1a725565e73a8,task=manager,pid=966,uid=0"
31
+ )
29
32
30
- func TestGetContainerName (t * testing.T ) {
33
+ func TestGetLegacyContainerName (t * testing.T ) {
31
34
currentOomInstance := new (OomInstance )
32
- err := getContainerName (startLine , currentOomInstance )
35
+ finished , err := getContainerName (startLine , currentOomInstance )
33
36
if err != nil {
34
37
t .Errorf ("bad line fed to getContainerName should yield no error, but had error %v" , err )
35
38
}
39
+ if finished {
40
+ t .Errorf ("bad line fed to getContainerName should not result in a finished oom log, but it did" )
41
+ }
36
42
if currentOomInstance .ContainerName != "" {
37
43
t .Errorf ("bad line fed to getContainerName yielded no container name but set it to %s" , currentOomInstance .ContainerName )
38
44
}
39
- err = getContainerName (containerLine , currentOomInstance )
45
+ finished , err = getContainerName (legacyContainerLine , currentOomInstance )
40
46
if err != nil {
41
47
t .Errorf ("container line fed to getContainerName should yield no error, but had error %v" , err )
42
48
}
49
+ if finished {
50
+ t .Errorf ("getContainerName with the legacy log line should not result in a finished oom log, but it did" )
51
+
52
+ }
43
53
if currentOomInstance .ContainerName != "/mem2" {
44
54
t .Errorf ("getContainerName should have set containerName to /mem2, not %s" , currentOomInstance .ContainerName )
45
55
}
@@ -48,6 +58,43 @@ func TestGetContainerName(t *testing.T) {
48
58
}
49
59
}
50
60
61
+ func TestGetContainerName (t * testing.T ) {
62
+ currentOomInstance := new (OomInstance )
63
+ finished , err := getContainerName (startLine , currentOomInstance )
64
+ if err != nil {
65
+ t .Errorf ("bad line fed to getContainerName should yield no error, but had error %v" , err )
66
+ }
67
+ if finished {
68
+ t .Errorf ("bad line fed to getContainerName should not result in a finished oom log, but it did" )
69
+ }
70
+ if currentOomInstance .ContainerName != "" {
71
+ t .Errorf ("bad line fed to getContainerName yielded no container name but set it to %s" , currentOomInstance .ContainerName )
72
+ }
73
+ finished , err = getContainerName (containerLine , currentOomInstance )
74
+ if err != nil {
75
+ t .Errorf ("container line fed to getContainerName should yield no error, but had error %v" , err )
76
+ }
77
+ if ! finished {
78
+ t .Errorf ("getContainerName with the complete log line should result in a finished oom log, but it did not" )
79
+
80
+ }
81
+ if currentOomInstance .ContainerName != "/kubepods/burstable/podfbdfe8e3-1c87-4ff2-907c-b2ec8e25d012/ef807430361e6e82b45db92e2e9b6fbec98f419b12c591e655c1a725565e73a8" {
82
+ t .Errorf ("getContainerName should have set containerName to /kubepods/burstable/podfbdfe8e3-1c87-4ff2-907c-b2ec8e25d012/ef807430361e6e82b45db92e2e9b6fbec98f419b12c591e655c1a725565e73a8, not %s" , currentOomInstance .ContainerName )
83
+ }
84
+ if currentOomInstance .VictimContainerName != "/kubepods/burstable/podfbdfe8e3-1c87-4ff2-907" {
85
+ t .Errorf ("getContainerName should have set victimContainerName to /kubepods/burstable/podfbdfe8e3-1c87-4ff2-907, not %s" , currentOomInstance .VictimContainerName )
86
+ }
87
+ if currentOomInstance .Pid != 966 {
88
+ t .Errorf ("getContainerName should have set Pid to 966, not %d" , currentOomInstance .Pid )
89
+ }
90
+ if currentOomInstance .ProcessName != "manager" {
91
+ t .Errorf ("getContainerName should have set ProcessName to manager, not %s" , currentOomInstance .ProcessName )
92
+ }
93
+ if currentOomInstance .Constraint != "CONSTRAINT_MEMCG" {
94
+ t .Errorf ("getContainerName should have set ProcessName to CONSTRAINT_MEMCG, not %s" , currentOomInstance .Constraint )
95
+ }
96
+ }
97
+
51
98
func TestGetProcessNamePid (t * testing.T ) {
52
99
currentOomInstance := new (OomInstance )
53
100
couldParseLine , err := getProcessNamePid (startLine , currentOomInstance )
0 commit comments