Skip to content

Commit

Permalink
Make conditions sequence test less strict
Browse files Browse the repository at this point in the history
Validate for the existance of a pending and running condition from
a list of conditions. Do not assert for an exact list len. Look for
a pending and running condition inside the list via ContainElement,
instead of asserting against a particular list item.
  • Loading branch information
qu1queee committed Feb 4, 2021
1 parent c096acc commit 17d6f7b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions test/integration/buildruns_to_taskruns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
It("reflects a change from pending to running reason", func() {
buildRunWitcher, _, _ := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun))

// use a fakeTime to simplify tests
fakeTime := time.Date(1989, 05, 15, 00, 01, 01, 651387237, time.UTC)

var timeout = time.After(tb.TimeOut)
go func() {
<-timeout
Expand All @@ -109,6 +112,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
for event := range buildRunWitcher.ResultChan() {
condition := event.Object.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded)
if condition != nil {
condition.LastTransitionTime = metav1.Time{Time: fakeTime}
seq = append(seq, condition)
}

Expand All @@ -117,13 +121,25 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
buildRunWitcher.Stop()
}
}

Expect(len(seq)).To(Equal(2))
Expect(seq[0].Type).To(Equal(v1alpha1.Succeeded))
Expect(seq[0].Status).To(Equal(corev1.ConditionUnknown))
Expect(seq[0].Reason).To(Equal("Pending"))
Expect(seq[1].Type).To(Equal(v1alpha1.Succeeded))
Expect(seq[1].Reason).To(Equal("Running"))
// consider a longer sequence, for events where the cluster have
// insufficient resources, where the Reason will be ExceededNodeResources.
Expect(len(seq) >= 2).To(Equal(true))

// ensure the conditions move eventually from unknown into running
Expect(seq).Should(ContainElement(&v1alpha1.Condition{
Type: v1alpha1.Succeeded,
Status: corev1.ConditionUnknown,
LastTransitionTime: metav1.Time{Time: fakeTime},
Reason: "Pending",
Message: "Pending",
}))
Expect(seq).Should(ContainElement(&v1alpha1.Condition{
Type: v1alpha1.Succeeded,
Status: corev1.ConditionUnknown,
LastTransitionTime: metav1.Time{Time: fakeTime},
Reason: "Running",
Message: "Not all Steps in the Task have finished executing",
}))
})
})

Expand Down

0 comments on commit 17d6f7b

Please sign in to comment.