It("doesn't flush on startup", func() { Consistently(byteWriter.WriteInput.message).ShouldNot(Receive()) }) }) Context("messages larger than buffer size", func() { BeforeEach(func() { for uint64(len(messageBytes)) < bufferSize { messageBytes = append(messageBytes, messageBytes...) } }) It("writes message to client", func() { byteWriter.WriteOutput.sentLength <- len(prefixedMessage) bytesWritten, err := batcher.Write(messageBytes) Expect(err).ToNot(HaveOccurred()) Expect(bytesWritten).To(Equal(len(messageBytes))) Expect(byteWriter.WriteInput.message).To(Receive(Equal(prefixedMessage))) }) It("sends a sentMessages metric", func() { close(byteWriter.WriteOutput.sentLength) _, err := batcher.Write(messageBytes) Expect(err).ToNot(HaveOccurred()) Eventually(byteWriter.WriteInput.message).Should(Receive(Equal(prefixedMessage))) Eventually(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(1)) }) Context("the weighted writer errors once", func() {
It("doesn't flush on startup", func() { Consistently(byteWriter.WriteInput.Message).ShouldNot(Receive()) }) }) Context("messages larger than buffer size", func() { BeforeEach(func() { for uint64(len(messageBytes)) < bufferSize { messageBytes = append(messageBytes, messageBytes...) } }) It("writes message to client", func() { byteWriter.WriteOutput.SentLength <- len(prefixedMessage) bytesWritten, err := batcher.Write(messageBytes) Expect(err).ToNot(HaveOccurred()) Expect(bytesWritten).To(Equal(len(messageBytes))) Eventually(byteWriter.WriteInput.Message).Should(Receive(Equal(prefixedMessage))) }) It("sends a sentMessages metric", func() { close(byteWriter.WriteOutput.SentLength) _, err := batcher.Write(messageBytes) Expect(err).ToNot(HaveOccurred()) Eventually(byteWriter.WriteInput.Message).Should(Receive(Equal(prefixedMessage))) Eventually(mockBatcher.BatchAddCounterInput).Should(BeCalled( With("DopplerForwarder.sentMessages"), )) })