Skip to content

Commit

Permalink
Fixed test for Pending in subscriber_test
Browse files Browse the repository at this point in the history
[#152164959]
  • Loading branch information
flawedmatrix committed Dec 4, 2017
1 parent 2744d5f commit 471dc2e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions mbus/subscriber_test.go
Expand Up @@ -117,13 +117,38 @@ var _ = Describe("Subscriber", func() {
Expect(err).To(MatchError("subscriber: nil mbus client"))
})

Context("Pending", func() {
Describe("Pending", func() {
It("returns the subscription Pending value", func() {
process = ifrit.Invoke(sub)
Eventually(process.Ready()).Should(BeClosed())
msgs, err := sub.Pending()
Expect(msgs).To(BeNumerically(">=", 0))

signal := make(chan struct{})
registry.RegisterStub = func(uri route.Uri, endpoint *route.Endpoint) {
<-signal
}

msg := mbus.RegistryMessage{Port: 8080, Uris: []route.Uri{"foo.example.com"}}
data, err := json.Marshal(msg)
Expect(err).NotTo(HaveOccurred())

err = natsClient.Publish("router.register", data)
Expect(err).ToNot(HaveOccurred())
err = natsClient.Publish("router.register", data)
Expect(err).ToNot(HaveOccurred())

Eventually(func() int {
msgs, err := sub.Pending()
Expect(err).ToNot(HaveOccurred())
return msgs
}).Should(Equal(1))

signal <- struct{}{}

Eventually(func() int {
msgs, err := sub.Pending()
Expect(err).ToNot(HaveOccurred())
return msgs
}).Should(Equal(0))
})

Context("when subscription is nil", func() {
Expand Down

0 comments on commit 471dc2e

Please sign in to comment.