mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Fix flake in gc test
This commit is contained in:
parent
44b0bb1ae7
commit
9bf88ddc6f
@ -60,32 +60,36 @@ func (f *FakePodControl) clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGC(t *testing.T) {
|
func TestGC(t *testing.T) {
|
||||||
|
type nameToPhase struct {
|
||||||
|
name string
|
||||||
|
phase api.PodPhase
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
pods map[string]api.PodPhase
|
pods []nameToPhase
|
||||||
threshold int
|
threshold int
|
||||||
deletedPodNames sets.String
|
deletedPodNames sets.String
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
pods: map[string]api.PodPhase{
|
pods: []nameToPhase{
|
||||||
"a": api.PodFailed,
|
{name: "a", phase: api.PodFailed},
|
||||||
"b": api.PodSucceeded,
|
{name: "b", phase: api.PodSucceeded},
|
||||||
},
|
},
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
deletedPodNames: sets.NewString("a", "b"),
|
deletedPodNames: sets.NewString("a", "b"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pods: map[string]api.PodPhase{
|
pods: []nameToPhase{
|
||||||
"a": api.PodFailed,
|
{name: "a", phase: api.PodFailed},
|
||||||
"b": api.PodSucceeded,
|
{name: "b", phase: api.PodSucceeded},
|
||||||
},
|
},
|
||||||
threshold: 1,
|
threshold: 1,
|
||||||
deletedPodNames: sets.NewString("a"),
|
deletedPodNames: sets.NewString("a"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pods: map[string]api.PodPhase{
|
pods: []nameToPhase{
|
||||||
"a": api.PodFailed,
|
{name: "a", phase: api.PodFailed},
|
||||||
"b": api.PodSucceeded,
|
{name: "b", phase: api.PodSucceeded},
|
||||||
},
|
},
|
||||||
threshold: 5,
|
threshold: 5,
|
||||||
deletedPodNames: sets.NewString(),
|
deletedPodNames: sets.NewString(),
|
||||||
@ -99,11 +103,11 @@ func TestGC(t *testing.T) {
|
|||||||
gcc.podControl = fake
|
gcc.podControl = fake
|
||||||
|
|
||||||
creationTime := time.Unix(0, 0)
|
creationTime := time.Unix(0, 0)
|
||||||
for name, phase := range test.pods {
|
for _, pod := range test.pods {
|
||||||
creationTime = creationTime.Add(1 * time.Hour)
|
creationTime = creationTime.Add(1 * time.Hour)
|
||||||
gcc.podStore.Store.Add(&api.Pod{
|
gcc.podStore.Store.Add(&api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{Name: name, CreationTimestamp: unversioned.Time{creationTime}},
|
ObjectMeta: api.ObjectMeta{Name: pod.name, CreationTimestamp: unversioned.Time{creationTime}},
|
||||||
Status: api.PodStatus{Phase: phase},
|
Status: api.PodStatus{Phase: pod.phase},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +123,7 @@ func TestGC(t *testing.T) {
|
|||||||
pass = false
|
pass = false
|
||||||
}
|
}
|
||||||
if !pass {
|
if !pass {
|
||||||
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v", i, test.deletedPodNames.List(), fake.deletePodName)
|
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v", i, test.deletedPodNames, fake.deletePodName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user