Skip to content

Commit

Permalink
[FAB-9693] Handle async container removal
Browse files Browse the repository at this point in the history
Switch to use Eventually to validate the container is deleted.

The naming function was also change to lower-case the generated name.

Change-Id: I82a423058dda011ad0b1c041d1b04ef7edb9b639
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Apr 25, 2018
1 parent 0cac65b commit 154cebd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion integration/runner/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -38,7 +39,9 @@ var DefaultNamer NameFunc = UniqueName
// UniqueName is a NamerFunc that generates base-32 enocded UUIDs for container
// names.
func UniqueName() string {
return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(util.GenerateBytesUUID())
uuid := util.GenerateBytesUUID()
encoded := base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(uuid)
return strings.ToLower(encoded)
}

// CouchDB manages the execution of an instance of a dockerized CounchDB
Expand Down
13 changes: 9 additions & 4 deletions integration/runner/couchdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,24 @@ var _ = Describe("CouchDB Runner", func() {
})

It("starts and stops a docker container with the specified image", func() {
containerName := runner.DefaultNamer()

By("using a real docker daemon")
client, err := docker.NewClientFromEnv()
Expect(err).NotTo(HaveOccurred())
couchDB.Client = nil
couchDB.StartTimeout = 0
couchDB.Name = containerName

By("starting couch DB")
process = ifrit.Invoke(couchDB)
Eventually(process.Ready(), runner.DefaultStartTimeout).Should(BeClosed())
Consistently(process.Wait()).ShouldNot(Receive())

By("inspecting the container by name")
container, err := client.InspectContainer("container-name")
container, err := client.InspectContainer(containerName)
Expect(err).NotTo(HaveOccurred())
Expect(container.Name).To(Equal("/container-name"))
Expect(container.Name).To(Equal("/" + containerName))
Expect(container.State.Status).To(Equal("running"))
Expect(container.Config).NotTo(BeNil())
Expect(container.Config.Image).To(Equal("hyperledger/fabric-couchdb:latest"))
Expand All @@ -195,8 +198,10 @@ var _ = Describe("CouchDB Runner", func() {
Eventually(process.Wait()).Should(Receive(BeNil()))
process = nil

_, err = client.InspectContainer("container-name")
Expect(err).To(MatchError("No such container: container-name"))
Eventually(func() error {
_, err = client.InspectContainer(containerName)
return err
}).Should(MatchError("No such container: " + containerName))
})

It("can be started and stopped with ifrit", func() {
Expand Down

0 comments on commit 154cebd

Please sign in to comment.