Skip to content

Commit

Permalink
Updating the E2e Test "TestIdlerAndPriorityClass" (#874)
Browse files Browse the repository at this point in the history
* Updating the E2e Test "TestIdlerAndPriorityClass"

Signed-off-by: Feny Mehta <[email protected]>

* Modifying as per review comments

Signed-off-by: Feny Mehta <[email protected]>

* Fixing the e2e test failure as per review comments

Signed-off-by: Feny Mehta <[email protected]>

* fixing the outcomes

Signed-off-by: Feny Mehta <[email protected]>

* Updating the name of the function

Signed-off-by: Feny Mehta <[email protected]>

* Updating as per review comments

Signed-off-by: Feny Mehta <[email protected]>

* Fixing  the go lint-error lint

Signed-off-by: Feny Mehta <[email protected]>

---------

Signed-off-by: Feny Mehta <[email protected]>
  • Loading branch information
fbm3307 authored Jan 17, 2024
1 parent 9bf98b8 commit 5c2eefd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
11 changes: 5 additions & 6 deletions test/e2e/parallel/user_workloads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -71,8 +70,8 @@ func TestIdlerAndPriorityClass(t *testing.T) {
require.NoError(t, err)
_, err = memberAwait.WaitForPods(t, "workloads-noise", len(externalNsPodsNoise), wait.PodRunning(), wait.WithPodLabel("idler", "idler"), wait.WithOriginalPriorityClass())
require.NoError(t, err)
_, err = hostAwait.WithRetryOptions(wait.TimeoutOption(10*time.Second)).WaitForNotificationWithName(t, "test-idler-stage-idled", toolchainv1alpha1.NotificationTypeIdled, wait.UntilNotificationHasConditions(wait.Sent()))
require.True(t, errors.IsNotFound(err))
err = hostAwait.WaitForNotificationToNotBeCreated(t, "test-idler-stage-idled")
require.NoError(t, err)

// Check if notification has been deleted before creating another pod
err = hostAwait.WaitUntilNotificationWithNameDeleted(t, "test-idler-dev-idled")
Expand All @@ -88,8 +87,8 @@ func TestIdlerAndPriorityClass(t *testing.T) {
time.Sleep(time.Duration(2*idler.Spec.TimeoutSeconds) * time.Second)
err = memberAwait.WaitUntilPodDeleted(t, pod.Namespace, pod.Name)
require.NoError(t, err)
_, err = hostAwait.WithRetryOptions(wait.TimeoutOption(10*time.Second)).WaitForNotificationWithName(t, "test-idler-dev-idled", toolchainv1alpha1.NotificationTypeIdled, wait.UntilNotificationHasConditions(wait.Sent()))
require.True(t, errors.IsNotFound(err))
err = hostAwait.WaitForNotificationToNotBeCreated(t, "test-idler-dev-idled")
require.NoError(t, err)

// There should not be any pods left in the namespace
err = memberAwait.WaitUntilPodsDeleted(t, idler.Name, wait.WithPodLabel("idler", "idler"))
Expand Down Expand Up @@ -247,7 +246,7 @@ func podSpec() corev1.PodSpec {
TerminationGracePeriodSeconds: &zero,
Containers: []corev1.Container{{
Name: "sleep",
Image: "busybox",
Image: "quay.io/prometheus/busybox:latest",
Command: []string{"sleep", "36000"}, // 10 hours
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down
39 changes: 33 additions & 6 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/codeready-toolchain/toolchain-common/pkg/test"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
testutil "github.com/codeready-toolchain/toolchain-e2e/testsupport/util"

"github.com/davecgh/go-spew/spew"
"github.com/ghodss/yaml"
goerr "github.com/pkg/errors"
"github.com/redhat-cop/operator-utils/pkg/util"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1175,9 +1175,13 @@ func (a *HostAwaitility) WaitForNotifications(t *testing.T, username, notificati
// WaitForNotificationWithName waits until there is an expected Notifications available with the provided name and with the notification type and which match the conditions (if provided).
func (a *HostAwaitility) WaitForNotificationWithName(t *testing.T, notificationName, notificationType string, criteria ...NotificationWaitCriterion) (toolchainv1alpha1.Notification, error) {
t.Logf("waiting for notification with name '%s'", notificationName)
var notification toolchainv1alpha1.Notification
notification := &toolchainv1alpha1.Notification{}
err := wait.Poll(a.RetryInterval, a.Timeout, func() (done bool, err error) {
if err := a.Client.Get(context.TODO(), types.NamespacedName{Name: notificationName, Namespace: a.Namespace}, &notification); err != nil {
notification = &toolchainv1alpha1.Notification{}
if err := a.Client.Get(context.TODO(), types.NamespacedName{Name: notificationName, Namespace: a.Namespace}, notification); err != nil {
if errors.IsNotFound(err) {
return false, nil
}
return false, err
}
if typeFound, found := notification.GetLabels()[toolchainv1alpha1.NotificationTypeLabelKey]; !found {
Expand All @@ -1186,13 +1190,36 @@ func (a *HostAwaitility) WaitForNotificationWithName(t *testing.T, notificationN
return false, fmt.Errorf("notification found with name does not have the expected type")
}

return matchNotificationWaitCriterion([]toolchainv1alpha1.Notification{notification}, criteria...), nil
return matchNotificationWaitCriterion([]toolchainv1alpha1.Notification{*notification}, criteria...), nil
})
// no match found, print the diffs
if err != nil {
a.printNotificationWaitCriterionDiffs(t, []toolchainv1alpha1.Notification{notification}, criteria...)
a.printNotificationWaitCriterionDiffs(t, []toolchainv1alpha1.Notification{*notification}, criteria...)
}
return notification, err
return *notification, err
}

// WaitForNotificationToBeNotCreated waits and checks that notification is NOT created.
func (a *HostAwaitility) WaitForNotificationToNotBeCreated(t *testing.T, notificationName string) error {
t.Logf("waiting to check notification with name '%s' is NOT created", notificationName)
notification := &toolchainv1alpha1.Notification{}
err := wait.Poll(a.RetryInterval, 10*time.Second, func() (done bool, err error) {
notification = &toolchainv1alpha1.Notification{}
if err := a.Client.Get(context.TODO(), types.NamespacedName{Name: notificationName, Namespace: a.Namespace}, notification); err != nil {
if errors.IsNotFound(err) {
return false, nil
}
return false, err
}
return true, nil
})
if err == nil {
return fmt.Errorf("notification '%s' was found, but it was expected to not be created/present: \n %v", notificationName, notification)
}
if goerr.Is(err, wait.ErrWaitTimeout) {
return nil
}
return err
}

// WaitUntilNotificationsDeleted waits until the Notification for the given user is deleted (ie, not found)
Expand Down

0 comments on commit 5c2eefd

Please sign in to comment.