close(stopChannel)
			Eventually(done).Should(BeClosed())
		})
	})

	Context("as a channel", func() {
		JustBeforeEach(func() {
			go buffer.Run()
		})

		It("works like a channel", func() {

			sendLogMessages("message 1", inMessageChan)

			readMessage := <-buffer.GetOutputChannel()
			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

			sendLogMessages("message 2", inMessageChan)

			readMessage2 := <-buffer.GetOutputChannel()
			Expect(readMessage2.GetLogMessage().GetMessage()).To(ContainSubstring("message 2"))

		})

		Context("tracking dropped messages", func() {
			var fakeEventEmitter *fake.FakeEventEmitter

			BeforeEach(func() {
				fakeEventEmitter = fake.NewFakeEventEmitter("doppler")
				sender := metric_sender.NewMetricSender(fakeEventEmitter)
Ejemplo n.º 2
0
				})

				It("keeps track of dropped messages", func() {
					Eventually(fakeEventEmitter.GetMessages).Should(HaveLen(1))
					Expect(fakeEventEmitter.GetMessages()[0].Event.(*events.CounterEvent)).To(Equal(&events.CounterEvent{
						Name:  proto.String("TruncatingBuffer.totalDroppedMessages"),
						Delta: proto.Uint64(uint64(total)),
					}))
				})
			}

			Context("when the buffer fills once", func() {
				JustBeforeEach(func() {
					Expect(buffer.GetDroppedMessageCount()).To(BeZero())

					firstBuffer := buffer.GetOutputChannel()
					sendLogMessages("message 1", inMessageChan)
					sendLogMessages("message 2", inMessageChan)
					sendLogMessages("message 3", inMessageChan)
					sendLogMessages("message 4", inMessageChan)

					Eventually(buffer.GetOutputChannel).ShouldNot(Equal(firstBuffer))
				})

				tracksDroppedMessages("drops all the messages", 3, 3)

				Context("when the buffer fills multiple times", func() {
					var receiveEvents int
					var sendLog int

					JustBeforeEach(func() {