-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extended test for serial scheduling
- Loading branch information
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package builds | ||
|
||
import ( | ||
"strings" | ||
|
||
g "github.com/onsi/ginkgo" | ||
o "github.com/onsi/gomega" | ||
|
||
buildapi "github.com/openshift/origin/pkg/build/api" | ||
buildutil "github.com/openshift/origin/pkg/build/util" | ||
exutil "github.com/openshift/origin/test/extended/util" | ||
kapi "k8s.io/kubernetes/pkg/api" | ||
) | ||
|
||
var _ = g.Describe("[builds][Slow] builds are executed in sequence", func() { | ||
defer g.GinkgoRecover() | ||
var ( | ||
// Use invalid source here as we don't care about the result | ||
buildFixture = exutil.FixturePath("..", "extended", "fixtures", "test-build-invalid-source.json") | ||
oc = exutil.NewCLI("cli-serial-builds", exutil.KubeConfigPath()) | ||
) | ||
|
||
g.JustBeforeEach(func() { | ||
g.By("waiting for builder service account") | ||
err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace())) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
oc.Run("create").Args("-f", buildFixture).Execute() | ||
}) | ||
|
||
g.Describe("start multiple builds simultaneously", func() { | ||
g.It("should start multiple build simultaneously and verify the execution order", func() { | ||
g.By("starting the build with --wait flag") | ||
var ( | ||
startSequence []string | ||
executionSequence []string | ||
) | ||
|
||
for i := 0; i < 3; i++ { | ||
out, err := oc.Run("start-build").Args("sample-build").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
startSequence = append(startSequence, strings.TrimSpace(out)) | ||
} | ||
|
||
buildsRunning := func() int { | ||
running := 0 | ||
buildutil.BuildConfigBuilds(oc.REST().Builds(oc.Namespace()), "sample-build", func(b buildapi.Build) bool { | ||
switch b.Status.Phase { | ||
case buildapi.BuildPhaseRunning, buildapi.BuildPhasePending: | ||
running++ | ||
return false | ||
} | ||
return false | ||
}) | ||
return running | ||
} | ||
|
||
buildWatch, err := oc.REST().Builds(oc.Namespace()).Watch(kapi.ListOptions{}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
defer buildWatch.Stop() | ||
for { | ||
event := <-buildWatch.ResultChan() | ||
build := event.Object.(*buildapi.Build) | ||
if build.Status.Phase == buildapi.BuildPhasePending { | ||
// There should be always just one running/pending build at the time | ||
o.Expect(buildsRunning()).Should(o.BeEquivalentTo(1)) | ||
found := false | ||
for _, name := range executionSequence { | ||
if found = name == build.Name; found { | ||
break | ||
} | ||
} | ||
if !found { | ||
executionSequence = append(executionSequence, build.Name) | ||
} | ||
} | ||
if len(executionSequence) == len(startSequence) { | ||
break | ||
} | ||
} | ||
|
||
// Expect the builds are started in same order as they were created | ||
o.Expect(startSequence).Should(o.BeEquivalentTo(executionSequence)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"kind": "List", | ||
"apiVersion": "v1", | ||
"metadata": {}, | ||
"items": [ | ||
{ | ||
"kind": "ImageStream", | ||
"apiVersion": "v1", | ||
"metadata": { | ||
"name": "origin-ruby-sample", | ||
"creationTimestamp": null | ||
}, | ||
"spec": {}, | ||
"status": { | ||
"dockerImageRepository": "" | ||
} | ||
}, | ||
{ | ||
"kind": "BuildConfig", | ||
"apiVersion": "v1", | ||
"metadata": { | ||
"name": "sample-build", | ||
"creationTimestamp": null | ||
}, | ||
"spec": { | ||
"triggers": [ | ||
{ | ||
"type": "imageChange", | ||
"imageChange": {} | ||
} | ||
], | ||
"source": { | ||
"type": "Git", | ||
"git": { | ||
"uri": "git://invalid-source" | ||
} | ||
}, | ||
"strategy": { | ||
"type": "Source", | ||
"sourceStrategy": { | ||
"from": { | ||
"kind": "DockerImage", | ||
"name": "centos/ruby-22-centos7" | ||
} | ||
} | ||
}, | ||
"resources": {} | ||
}, | ||
"status": { | ||
"lastVersion": 0 | ||
} | ||
} | ||
] | ||
} |