Improve e2e tests - add waitForJobToFinish
This commit is contained in:
parent
43b75b0775
commit
aeed89f3b0
|
|
@ -3,15 +3,15 @@ package e2e
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jenkinsci/kubernetes-operator/internal/try"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/groovy"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/bndr/gojenkins"
|
||||
framework "github.com/operator-framework/operator-sdk/pkg/test"
|
||||
|
|
@ -129,18 +129,7 @@ func TestPlugins(t *testing.T) {
|
|||
i, err := job.InvokeSimple(map[string]string{})
|
||||
require.NoError(t, err, i)
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
err = try.Until(func() (end bool, err error) {
|
||||
running, _ := job.IsRunning()
|
||||
queued, _ := job.IsQueued()
|
||||
|
||||
if !running && !queued {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}, time.Second*5, time.Minute*2)
|
||||
require.NoError(t, err)
|
||||
waitForJobToFinish(t, job, 2 * time.Second, 2 * time.Minute)
|
||||
|
||||
job, err = jenkinsClient.GetJob(jobID)
|
||||
require.NoError(t, err, job)
|
||||
|
|
|
|||
|
|
@ -36,20 +36,8 @@ func TestBackupAndRestore(t *testing.T) {
|
|||
require.NoError(t, err, job)
|
||||
i, err := job.InvokeSimple(map[string]string{})
|
||||
require.NoError(t, err, i)
|
||||
|
||||
time.Sleep(time.Second * 10)
|
||||
err = try.Until(func() (end bool, err error) {
|
||||
t.Log("Running job...")
|
||||
running, _ := job.IsRunning()
|
||||
queued, _ := job.IsQueued()
|
||||
|
||||
if !running && !queued {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}, time.Second*10, time.Minute*2)
|
||||
require.NoError(t, err)
|
||||
// FIXME: waitForJobToFinish use
|
||||
time.Sleep(60 * time.Second) // wait for the build to complete
|
||||
|
||||
restartJenkinsMasterPod(t, jenkins)
|
||||
waitForRecreateJenkinsMasterPod(t, jenkins)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package e2e
|
|||
|
||||
import (
|
||||
goctx "context"
|
||||
"github.com/bndr/gojenkins"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -29,6 +30,28 @@ var (
|
|||
// checkConditionFunc is used to check if a condition for the jenkins CR is set
|
||||
type checkConditionFunc func(*v1alpha2.Jenkins, error) bool
|
||||
|
||||
func waitForJobToFinish(t *testing.T, job *gojenkins.Job, tick, timeout time.Duration) {
|
||||
err := try.Until(func() (end bool, err error) {
|
||||
t.Logf("Waiting for job `%s` to finish", job.GetName())
|
||||
running, err := job.IsRunning()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
queued, err := job.IsQueued()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if !running && !queued {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}, tick, timeout)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
t.Log("Waiting for Jenkins base configuration to complete")
|
||||
_, err := WaitUntilJenkinsConditionSet(retryInterval, 150, jenkins, func(jenkins *v1alpha2.Jenkins, err error) bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue