Skip to content

Commit 04c6d93

Browse files
committed
Check for restarts without being affected by container startup order
The test for checking container restarts in a Pod with restartable-init-1 and regular-1 is flaky. Right now, when we check if restartable-init-1 has restarted, we see if it hasn’t written the "Started" log after regular-1 has written its "Started" log. But even though the startup sequence starts with restartable-init-1 and then regular-1, there’s no guarantee they’ll finish starting up in that order. Sometimes regular-1 finishes first and writes its "Started" log before restartable-init-1. 1. restartable-init-1 Starting 2. regular-1 Starting 3. regular-1 Started 4. restartable-init-1 Started In this test, the startup order doesn’t really matter; all we need to check is if restartable-init-1 restarted. So I changed the test to simply look for more than one "Starting" log in restartable-init-1's logs. There were other places that used the same helper function DoesntStartAfter, so replaced those as well and deleted the helper function.
1 parent 4812ea8 commit 04c6d93

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

test/e2e_node/container_lifecycle_pod_construction.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,6 @@ func (o containerOutputList) StartsBefore(lhs, rhs string) error {
179179
return nil
180180
}
181181

182-
// DoesntStartAfter returns an error if lhs started after rhs
183-
func (o containerOutputList) DoesntStartAfter(lhs, rhs string) error {
184-
rhsStart := o.findIndex(rhs, "Starting", 0)
185-
186-
if rhsStart == -1 {
187-
return fmt.Errorf("couldn't find that %s ever started, got\n%v", rhs, o)
188-
}
189-
190-
// this works even for the same names (restart case)
191-
lhsStart := o.findIndex(lhs, "Started", rhsStart+1)
192-
193-
if lhsStart != -1 {
194-
return fmt.Errorf("expected %s to not start after %s, got\n%v", lhs, rhs, o)
195-
}
196-
197-
return nil
198-
}
199-
200182
// ExitsBefore returns an error if lhs did not end before rhs
201183
func (o containerOutputList) ExitsBefore(lhs, rhs string) error {
202184
lhsExit := o.findIndex(lhs, "Exiting", 0)

test/e2e_node/container_lifecycle_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
16311631
results = parseOutput(context.TODO(), f, podSpec)
16321632
})
16331633
ginkgo.It("should not restart a restartable init container", func() {
1634-
framework.ExpectNoError(results.DoesntStartAfter(restartableInit1, regular1))
1634+
framework.ExpectNoError(results.HasNotRestarted(restartableInit1))
16351635
})
16361636
ginkgo.It("should run a regular container to completion", func() {
16371637
framework.ExpectNoError(results.Exits(regular1))
@@ -2033,7 +2033,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
20332033
results = parseOutput(context.TODO(), f, podSpec)
20342034
})
20352035
ginkgo.It("should not restart a restartable init container", func() {
2036-
framework.ExpectNoError(results.DoesntStartAfter(restartableInit1, regular1))
2036+
framework.ExpectNoError(results.HasNotRestarted(restartableInit1))
20372037
})
20382038
ginkgo.It("should run a regular container to completion", func() {
20392039
framework.ExpectNoError(results.Exits(regular1))
@@ -2454,7 +2454,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
24542454
})
24552455

24562456
ginkgo.It("should not restart a restartable init container", func() {
2457-
framework.ExpectNoError(results.DoesntStartAfter(restartableInit1, regular1))
2457+
framework.ExpectNoError(results.HasNotRestarted(restartableInit1))
24582458
})
24592459
// this test case is different from restartPolicy=Never
24602460
ginkgo.It("should start a regular container", func() {

0 commit comments

Comments
 (0)