Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Move test assertions out of range(chan)
Browse files Browse the repository at this point in the history
This pattern of calling range on a channel and asserting that one item
matches our test assertions will fail to raise an error if the queue is
empty.

So instead change these to read a single item from the channel, which will
block if the channel is empty, and then make the assertion. I've added a
done channel so that Ginkgo fails the test if we block for longer than the
default of 1s:

http://onsi.github.io/ginkgo/#asynchronous-tests
  • Loading branch information
dcarley committed Jul 4, 2014
1 parent 959a876 commit c72a9bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions queue/queue_connection_test.go
Expand Up @@ -127,7 +127,7 @@ var _ = Describe("QueueConnection", func() {
Expect(err).To(BeNil())
})

It("should consume and publish messages onto the provided queue and exchange", func() {
It("should consume and publish messages onto the provided queue and exchange", func(done Done) {
err = consumer.ExchangeDeclare(exchangeName, "direct")
Expect(err).To(BeNil())

Expand All @@ -143,11 +143,10 @@ var _ = Describe("QueueConnection", func() {
err = publisher.Publish(exchangeName, "#", "text/plain", "foo")
Expect(err).To(BeNil())

for d := range deliveries {
Expect(string(d.Body)).To(Equal("foo"))
d.Ack(false)
break
}
item := <-deliveries
Expect(string(item.Body)).To(Equal("foo"))
item.Ack(false)
close(done)
})
})
})
11 changes: 5 additions & 6 deletions queue/queue_manager_test.go
Expand Up @@ -72,18 +72,17 @@ var _ = Describe("QueueManager", func() {
Expect(err).To(BeNil())
})

It("can consume and publish to the AMQP service", func() {
It("can consume and publish to the AMQP service", func(done Done) {
deliveries, err := queueManager.Consume()
Expect(err).To(BeNil())

err = queueManager.Publish("#", "text/plain", "foo")
Expect(err).To(BeNil())

for d := range deliveries {
Expect(string(d.Body)).To(Equal("foo"))
d.Ack(false)
break
}
item := <-deliveries
Expect(string(item.Body)).To(Equal("foo"))
item.Ack(false)
close(done)
})
})
})

0 comments on commit c72a9bc

Please sign in to comment.