@@ -58,25 +58,47 @@ func TestDoProbe(t *testing.T) {
58
58
failedStatus .Phase = v1 .PodFailed
59
59
60
60
tests := []struct {
61
- probe v1.Probe
62
- podStatus * v1.PodStatus
63
- expectContinue bool
64
- expectSet bool
65
- expectedResult results.Result
61
+ probe v1.Probe
62
+ podStatus * v1.PodStatus
63
+ expectContinue map [string ]bool
64
+ expectSet bool
65
+ expectedResult results.Result
66
+ setDeletionTimestamp bool
66
67
}{
67
68
{ // No status.
68
- expectContinue : true ,
69
+ expectContinue : map [string ]bool {
70
+ liveness .String (): true ,
71
+ readiness .String (): true ,
72
+ startup .String (): true ,
73
+ },
69
74
},
70
75
{ // Pod failed
71
76
podStatus : & failedStatus ,
72
77
},
78
+ { // Pod deletion
79
+ podStatus : & runningStatus ,
80
+ setDeletionTimestamp : true ,
81
+ expectSet : true ,
82
+ expectContinue : map [string ]bool {
83
+ readiness .String (): true ,
84
+ },
85
+ expectedResult : results .Success ,
86
+ },
73
87
{ // No container status
74
- podStatus : & otherStatus ,
75
- expectContinue : true ,
88
+ podStatus : & otherStatus ,
89
+ expectContinue : map [string ]bool {
90
+ liveness .String (): true ,
91
+ readiness .String (): true ,
92
+ startup .String (): true ,
93
+ },
76
94
},
77
95
{ // Container waiting
78
- podStatus : & pendingStatus ,
79
- expectContinue : true ,
96
+ podStatus : & pendingStatus ,
97
+ expectContinue : map [string ]bool {
98
+ liveness .String (): true ,
99
+ readiness .String (): true ,
100
+ startup .String (): true ,
101
+ },
80
102
expectSet : true ,
81
103
expectedResult : results .Failure ,
82
104
},
@@ -86,8 +108,12 @@ func TestDoProbe(t *testing.T) {
86
108
expectedResult : results .Failure ,
87
109
},
88
110
{ // Probe successful.
89
- podStatus : & runningStatus ,
90
- expectContinue : true ,
111
+ podStatus : & runningStatus ,
112
+ expectContinue : map [string ]bool {
113
+ liveness .String (): true ,
114
+ readiness .String (): true ,
115
+ startup .String (): true ,
116
+ },
91
117
expectSet : true ,
92
118
expectedResult : results .Success ,
93
119
},
@@ -96,7 +122,11 @@ func TestDoProbe(t *testing.T) {
96
122
probe : v1.Probe {
97
123
InitialDelaySeconds : - 100 ,
98
124
},
99
- expectContinue : true ,
125
+ expectContinue : map [string ]bool {
126
+ liveness .String (): true ,
127
+ readiness .String (): true ,
128
+ startup .String (): true ,
129
+ },
100
130
expectSet : true ,
101
131
expectedResult : results .Success ,
102
132
},
@@ -107,8 +137,12 @@ func TestDoProbe(t *testing.T) {
107
137
if test .podStatus != nil {
108
138
m .statusManager .SetPodStatus (w .pod , * test .podStatus )
109
139
}
110
- if c := w .doProbe (); c != test .expectContinue {
111
- t .Errorf ("[%s-%d] Expected continue to be %v but got %v" , probeType , i , test .expectContinue , c )
140
+ if test .setDeletionTimestamp {
141
+ now := metav1 .Now ()
142
+ w .pod .ObjectMeta .DeletionTimestamp = & now
143
+ }
144
+ if c := w .doProbe (); c != test .expectContinue [probeType .String ()] {
145
+ t .Errorf ("[%s-%d] Expected continue to be %v but got %v" , probeType , i , test .expectContinue [probeType .String ()], c )
112
146
}
113
147
result , ok := resultsManager (m , probeType ).Get (testContainerID )
114
148
if ok != test .expectSet {
@@ -299,6 +333,12 @@ func expectContinue(t *testing.T, w *worker, c bool, msg string) {
299
333
}
300
334
}
301
335
336
+ func expectStop (t * testing.T , w * worker , c bool , msg string ) {
337
+ if c {
338
+ t .Errorf ("[%s - %s] Expected to stop, but did not" , w .probeType , msg )
339
+ }
340
+ }
341
+
302
342
func resultsManager (m * manager , probeType probeType ) results.Manager {
303
343
switch probeType {
304
344
case readiness :
@@ -468,6 +508,6 @@ func TestStartupProbeDisabledByStarted(t *testing.T) {
468
508
// startupProbe fails, but is disabled
469
509
m .prober .exec = fakeExecProber {probe .Failure , nil }
470
510
msg = "Started, probe failure, result success"
471
- expectContinue (t , w , w .doProbe (), msg )
511
+ expectStop (t , w , w .doProbe (), msg )
472
512
expectResult (t , w , results .Success , msg )
473
513
}
0 commit comments