Skip to content

Commit

Permalink
Add extended test for serial scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Apr 13, 2016
1 parent ad6d367 commit be72d42
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/extended/builds/serial.go
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))
})
})
})
54 changes: 54 additions & 0 deletions test/extended/fixtures/test-build-invalid-source.json
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
}
}
]
}

0 comments on commit be72d42

Please sign in to comment.