Skip to content

Commit

Permalink
node_e2e: refactor RunTogether function
Browse files Browse the repository at this point in the history
  • Loading branch information
bart0sh committed May 2, 2024
1 parent 82cd82a commit 6ecf0da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions test/e2e_node/container_lifecycle_pod_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,30 @@ func (o containerOutputList) String() string {
// RunTogether returns an error the lhs and rhs run together
func (o containerOutputList) RunTogether(lhs, rhs string) error {
lhsStart := o.findIndex(lhs, "Started", 0)
rhsStart := o.findIndex(rhs, "Started", 0)

lhsFinish := o.findIndex(lhs, "Exiting", 0)
rhsFinish := o.findIndex(rhs, "Exiting", 0)

if lhsStart == -1 {
return fmt.Errorf("couldn't find that %s ever started, got\n%v", lhs, o)
}

rhsStart := o.findIndex(rhs, "Started", lhsStart+1)
if rhsStart == -1 {
return fmt.Errorf("couldn't find that %s ever started, got\n%v", rhs, o)
}

if lhsFinish != -1 && rhsStart > lhsFinish {
lhsExit := o.findIndex(lhs, "Exiting", lhsStart+1)
if lhsExit == -1 {
return fmt.Errorf("couldn't find that %s ever exited, got\n%v", lhs, o)
}

if rhsStart > lhsExit {
return fmt.Errorf("expected %s to start before exiting %s, got\n%v", rhs, lhs, o)
}

if rhsFinish != -1 && lhsStart > rhsFinish {
rhsExit := o.findIndex(rhs, "Exiting", rhsStart+1)
if rhsExit == -1 {
return fmt.Errorf("couldn't find that %s ever exited, got\n%v", rhs, o)
}

if lhsStart > rhsExit {
return fmt.Errorf("expected %s to start before exiting %s, got\n%v", lhs, rhs, o)
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e_node/container_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
})

ginkgo.It("should run both restartable init containers and third init container together", func() {
framework.ExpectNoError(results.RunTogether(restartableInit2, restartableInit1))
framework.ExpectNoError(results.RunTogether(restartableInit1, restartableInit2))
framework.ExpectNoError(results.RunTogether(restartableInit1, init3))
framework.ExpectNoError(results.RunTogether(restartableInit2, init3))
})
Expand Down

0 comments on commit 6ecf0da

Please sign in to comment.