Merge pull request #57 from vdemeester/no-more-sleep-in-integration

Update integration setups to use libcompose events
This commit is contained in:
Emile Vauge 2015-10-12 15:43:08 +02:00
commit 31c7aba8c4
3 changed files with 55 additions and 25 deletions

10
Godeps/Godeps.json generated
View file

@ -189,19 +189,19 @@
"Rev": "f39987afe8d611407887b3094c03d6ba6a766a67" "Rev": "f39987afe8d611407887b3094c03d6ba6a766a67"
}, { }, {
"ImportPath": "github.com/docker/libcompose/docker", "ImportPath": "github.com/docker/libcompose/docker",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35" "Rev": "79ef5d150f053a5b12f16b02d8844ed7cf33611a"
}, { }, {
"ImportPath": "github.com/docker/libcompose/logger", "ImportPath": "github.com/docker/libcompose/logger",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35" "Rev": "79ef5d150f053a5b12f16b02d8844ed7cf33611a"
}, { }, {
"ImportPath": "github.com/docker/libcompose/lookup", "ImportPath": "github.com/docker/libcompose/lookup",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35" "Rev": "79ef5d150f053a5b12f16b02d8844ed7cf33611a"
}, { }, {
"ImportPath": "github.com/docker/libcompose/project", "ImportPath": "github.com/docker/libcompose/project",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35" "Rev": "79ef5d150f053a5b12f16b02d8844ed7cf33611a"
}, { }, {
"ImportPath": "github.com/docker/libcompose/utils", "ImportPath": "github.com/docker/libcompose/utils",
"Rev": "aad672800904307e96a2c21cad1420f3080e0f35" "Rev": "79ef5d150f053a5b12f16b02d8844ed7cf33611a"
}, { }, {
"ImportPath": "github.com/docker/libtrust", "ImportPath": "github.com/docker/libtrust",
"Rev": "9cbd2a1374f46905c68a4eb3694a130610adc62a" "Rev": "9cbd2a1374f46905c68a4eb3694a130610adc62a"

View file

@ -9,3 +9,36 @@
logLevel = "DEBUG" logLevel = "DEBUG"
[file] [file]
# rules
[backends]
[backends.backend1]
[backends.backend1.circuitbreaker]
expression = "NetworkErrorRatio() > 0.5"
[backends.backend1.servers.server1]
url = "http://172.17.0.2:80"
weight = 10
[backends.backend1.servers.server2]
url = "http://172.17.0.3:80"
weight = 1
[backends.backend2]
[backends.backend2.LoadBalancer]
method = "drr"
[backends.backend2.servers.server1]
url = "http://172.17.0.4:80"
weight = 1
[backends.backend2.servers.server2]
url = "http://172.17.0.5:80"
weight = 2
[frontends]
[frontends.frontend1]
backend = "backend2"
[frontends.frontend1.routes.test_1]
rule = "Host"
value = "test.localhost"
[frontends.frontend2]
backend = "backend1"
[frontends.frontend2.routes.test_2]
rule = "Path"
value = "/test"

View file

@ -9,7 +9,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"text/template" "text/template"
"time"
"github.com/docker/libcompose/docker" "github.com/docker/libcompose/docker"
"github.com/docker/libcompose/project" "github.com/docker/libcompose/project"
@ -72,7 +71,7 @@ func (s *MarathonSuite) SetUpSuite(c *check.C) {
type BaseSuite struct { type BaseSuite struct {
composeProject *project.Project composeProject *project.Project
listenChan chan project.ProjectEvent listenChan chan project.Event
started chan bool started chan bool
stopped chan bool stopped chan bool
deleted chan bool deleted chan bool
@ -82,14 +81,12 @@ func (s *BaseSuite) TearDownSuite(c *check.C) {
// shutdown and delete compose project // shutdown and delete compose project
if s.composeProject != nil { if s.composeProject != nil {
s.composeProject.Down() s.composeProject.Down()
// Waiting for libcompose#55 to be merged <-s.stopped
// <-s.stopped defer close(s.stopped)
time.Sleep(2 * time.Second)
s.composeProject.Delete() s.composeProject.Delete()
// Waiting for libcompose#55 to be merged <-s.deleted
// <-s.deleted defer close(s.deleted)
time.Sleep(2 * time.Second)
} }
} }
@ -103,32 +100,32 @@ func (s *BaseSuite) createComposeProject(c *check.C, name string) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
s.composeProject = composeProject s.composeProject = composeProject
s.listenChan = make(chan project.ProjectEvent) s.started = make(chan bool)
s.stopped = make(chan bool)
s.deleted = make(chan bool)
s.listenChan = make(chan project.Event)
go s.startListening(c) go s.startListening(c)
composeProject.AddListener(s.listenChan) composeProject.AddListener(s.listenChan)
composeProject.Start() composeProject.Start()
// FIXME Wait for compose to start // Wait for compose to start
// Waiting for libcompose#55 to be merged <-s.started
// <-s.started defer close(s.started)
time.Sleep(2 * time.Second)
} }
func (s *BaseSuite) startListening(c *check.C) { func (s *BaseSuite) startListening(c *check.C) {
for event := range s.listenChan { for event := range s.listenChan {
// FIXME Remove this when it's working (libcompose#55) // FIXME Add a timeout on event ?
// fmt.Fprintf(os.Stdout, "Event: %s (%v)\n", event.Event, event) if event.EventType == project.EventProjectStartDone {
// FIXME Add a timeout on event
if event.Event == project.PROJECT_UP_DONE {
s.started <- true s.started <- true
} }
if event.Event == project.PROJECT_DOWN_DONE { if event.EventType == project.EventProjectDownDone {
s.stopped <- true s.stopped <- true
} }
if event.Event == project.PROJECT_DELETE_DONE { if event.EventType == project.EventProjectDeleteDone {
s.deleted <- true s.deleted <- true
} }
} }