Skip to content

Commit

Permalink
Create common util package for integration and e2e tests with sleep/w…
Browse files Browse the repository at this point in the history
…ait constants
  • Loading branch information
mszadkow committed Oct 8, 2024
1 parent cc9c108 commit 983e2da
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion test/e2e/mpi_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
schedv1alpha1 "sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"

kubeflow "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1"
"github.com/kubeflow/mpi-operator/test/util"
)

var _ = ginkgo.Describe("MPIJob", func() {
Expand Down Expand Up @@ -172,7 +173,7 @@ var _ = ginkgo.Describe("MPIJob", func() {
ctx := context.Background()
mpiJob = createJob(ctx, mpiJob)

time.Sleep(1 * time.Second)
time.Sleep(util.SleepDurationControllerSyncDelay)
mpiJob, err := mpiClient.KubeflowV2beta1().MPIJobs(mpiJob.Namespace).Get(ctx, mpiJob.Name, metav1.GetOptions{})
gomega.Expect(err).To(gomega.BeNil())

Expand Down
3 changes: 2 additions & 1 deletion test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
volcanoclient "volcano.sh/apis/pkg/client/clientset/versioned"

clientset "github.com/kubeflow/mpi-operator/pkg/client/clientset/versioned"
"github.com/kubeflow/mpi-operator/test/util"
)

var (
Expand Down Expand Up @@ -191,7 +192,7 @@ func (c *eventChecker) run() {

func (c *eventChecker) verify(t *testing.T) {
t.Helper()
err := wait.PollUntilContextTimeout(context.Background(), waitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), util.WaitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
c.Lock()
defer c.Unlock()
return c.expected.Len() == 0, nil
Expand Down
16 changes: 6 additions & 10 deletions test/integration/mpi_job_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ import (
"github.com/kubeflow/mpi-operator/pkg/client/clientset/versioned/scheme"
informers "github.com/kubeflow/mpi-operator/pkg/client/informers/externalversions"
"github.com/kubeflow/mpi-operator/pkg/controller"
)

const (
waitInterval = 100 * time.Millisecond
moderateTimeout = 2 * time.Second
"github.com/kubeflow/mpi-operator/test/util"
)

func TestMPIJobSuccess(t *testing.T) {
Expand Down Expand Up @@ -693,7 +689,7 @@ func TestMPIJobWithSchedulerPlugins(t *testing.T) {
if err != nil {
t.Errorf("Failed sending job to apiserver: %v", err)
}
if err = wait.PollUntilContextTimeout(ctx, waitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
if err = wait.PollUntilContextTimeout(ctx, util.WaitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
pg, err := getSchedPodGroup(ctx, gangSchedulerCfg.schedClient, mpiJob)
if err != nil {
return false, err
Expand Down Expand Up @@ -809,7 +805,7 @@ func TestMPIJobWithVolcanoScheduler(t *testing.T) {
if err != nil {
t.Errorf("Failed sending job to apiserver: %v", err)
}
if err = wait.PollUntilContextTimeout(ctx, waitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
if err = wait.PollUntilContextTimeout(ctx, util.WaitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
pg, err := getVolcanoPodGroup(ctx, gangSchedulerCfg.volcanoClient, mpiJob)
if err != nil {
return false, err
Expand Down Expand Up @@ -877,7 +873,7 @@ func TestMPIJobManagedExternally(t *testing.T) {
t.Fatalf("Failed sending job to apiserver: %v", err)
}

time.Sleep(moderateTimeout)
time.Sleep(util.SleepDurationControllerSyncDelay)
// 2. Status is not getting updated
mpiJob = validateMPIJobStatus(ctx, t, s.mpiClient, mpiJob, nil)
if mpiJob.Status.StartTime != nil {
Expand Down Expand Up @@ -975,7 +971,7 @@ func validateMPIJobDependencies(
podGroup metav1.Object
)
var problems []string
if err := wait.PollUntilContextTimeout(ctx, waitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
if err := wait.PollUntilContextTimeout(ctx, util.WaitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
problems = nil
var err error
svc, err = getServiceForJob(ctx, kubeClient, job)
Expand Down Expand Up @@ -1071,7 +1067,7 @@ func validateMPIJobStatus(ctx context.Context, t *testing.T, client clientset.In
err error
got map[kubeflow.MPIReplicaType]*kubeflow.ReplicaStatus
)
if err := wait.PollUntilContextTimeout(ctx, waitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
if err := wait.PollUntilContextTimeout(ctx, util.WaitInterval, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) {
newJob, err = client.KubeflowV2beta1().MPIJobs(job.Namespace).Get(ctx, job.Name, metav1.GetOptions{})
if err != nil {
return false, err
Expand Down
23 changes: 23 additions & 0 deletions test/util/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 The Kubeflow Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import "time"

const (
// Time duration used to ensure that subsequent controller syncs have occurred
SleepDurationControllerSyncDelay = 1 * time.Second
WaitInterval = 100 * time.Millisecond
)

0 comments on commit 983e2da

Please sign in to comment.