Merge pull request #105 from jakalkhalili/wait-for-build
Improve e2e test with waiting enhancement
This commit is contained in:
commit
9e4ecb3c46
|
|
@ -6,12 +6,12 @@ import (
|
|||
"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"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
|
||||
"github.com/bndr/gojenkins"
|
||||
framework "github.com/operator-framework/operator-sdk/pkg/test"
|
||||
|
|
@ -129,7 +129,7 @@ func TestPlugins(t *testing.T) {
|
|||
i, err := job.InvokeSimple(map[string]string{})
|
||||
require.NoError(t, err, i)
|
||||
|
||||
time.Sleep(time.Minute * 2)
|
||||
waitForJobToFinish(t, job, 2 * time.Second, 2 * time.Minute)
|
||||
|
||||
job, err = jenkinsClient.GetJob(jobID)
|
||||
require.NoError(t, err, job)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func TestBackupAndRestore(t *testing.T) {
|
|||
require.NoError(t, err, job)
|
||||
i, err := job.InvokeSimple(map[string]string{})
|
||||
require.NoError(t, err, i)
|
||||
// FIXME: waitForJobToFinish use
|
||||
time.Sleep(60 * time.Second) // wait for the build to complete
|
||||
|
||||
restartJenkinsMasterPod(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