Skip to content

Commit

Permalink
verify the terminalState during integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 committed Jun 30, 2024
1 parent 674e80c commit faa89eb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ func JobSetCompleted(ctx context.Context, k8sClient client.Client, js *jobset.Jo
Status: metav1.ConditionTrue,
},
}
terminalState := string(jobset.JobSetCompleted)
gomega.Eventually(checkJobSetStatus, timeout, interval).WithArguments(ctx, k8sClient, js, conditions).Should(gomega.Equal(true))
gomega.Eventually(checkJobSetTerminalState, timeout, interval).WithArguments(ctx, k8sClient, js, terminalState).Should(gomega.Equal(true))
}

// JobSetFailed
func JobSetFailed(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, timeout time.Duration) {
ginkgo.By(fmt.Sprintf("checking jobset status is: %s", jobset.JobSetFailed))
conditions := []metav1.Condition{
Expand All @@ -71,7 +74,9 @@ func JobSetFailed(ctx context.Context, k8sClient client.Client, js *jobset.JobSe
Status: metav1.ConditionTrue,
},
}
terminalState := string(jobset.JobSetFailed)
gomega.Eventually(checkJobSetStatus, timeout, interval).WithArguments(ctx, k8sClient, js, conditions).Should(gomega.Equal(true))
gomega.Eventually(checkJobSetTerminalState, timeout, interval).WithArguments(ctx, k8sClient, js, terminalState).Should(gomega.Equal(true))
}

func JobSetSuspended(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, timeout time.Duration) {
Expand Down Expand Up @@ -142,6 +147,7 @@ func checkJobSetActive(ctx context.Context, k8sClient client.Client, js *jobset.
return true, nil
}

// checkJobSetStatus check if the JobSet status matches the expected conditions.
func checkJobSetStatus(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, conditions []metav1.Condition) (bool, error) {
var fetchedJS jobset.JobSet
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: js.Namespace, Name: js.Name}, &fetchedJS); err != nil {
Expand All @@ -158,6 +164,15 @@ func checkJobSetStatus(ctx context.Context, k8sClient client.Client, js *jobset.
return found == len(conditions), nil
}

// checkJobSetTerminalState check if the JobSet is in the expected terminal state.
func checkJobSetTerminalState(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, terminalState string) (bool, error) {
var fetchedJS jobset.JobSet
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: js.Namespace, Name: js.Name}, &fetchedJS); err != nil {
return false, err
}
return fetchedJS.Status.TerminalState == terminalState, nil
}

// DeleteNamespace deletes all objects the tests typically create in the namespace.
func DeleteNamespace(ctx context.Context, c client.Client, ns *corev1.Namespace) error {
if ns == nil {
Expand Down

0 comments on commit faa89eb

Please sign in to comment.