Eventually(wrappedEmitter.GetMessages).Should(HaveLen(2))

			message := wrappedEmitter.GetMessages()[1]
			hbEnvelope := &events.Envelope{}
			err := proto.Unmarshal(message, hbEnvelope)
			Expect(err).NotTo(HaveOccurred())

			hbEvent := hbEnvelope.GetHeartbeat()

			Expect(hbEvent.GetReceivedCount()).To(Equal(uint64(1)))
		})
	})

	Describe("Close", func() {
		var heartbeatResponder emitter.ByteEmitter

		BeforeEach(func() {
			heartbeatResponder, _ = emitter.NewHeartbeatResponder(wrappedEmitter, origin)
		})

		It("eventually delegates to the inner heartbeat emitter", func() {
			heartbeatResponder.Close()
			Eventually(wrappedEmitter.IsClosed).Should(BeTrue())
		})

		It("can be called more than once", func() {
			heartbeatResponder.Close()
			Expect(heartbeatResponder.Close).ToNot(Panic())
		})
	})
	Describe("Close()", func() {
		It("closes the UDP connection", func() {

			udpEmitter, _ := emitter.NewUdpEmitter("localhost:42420")

			udpEmitter.Close()

			err := udpEmitter.Emit(testData)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("use of closed network connection"))
		})
	})

	Describe("Emit()", func() {
		var udpEmitter emitter.ByteEmitter

		Context("when the agent is listening", func() {

			var agentListener net.PacketConn

			BeforeEach(func() {
				var err error
				agentListener, err = net.ListenPacket("udp4", "")
				Expect(err).ToNot(HaveOccurred())

				udpEmitter, err = emitter.NewUdpEmitter(agentListener.LocalAddr().String())
				Expect(err).ToNot(HaveOccurred())
			})

			AfterEach(func() {
			log.SetOutput(logWriter)

			hbEmitter, _ := emitter.NewHeartbeatEmitter(wrappedEmitter, origin)

			Eventually(func() int { return len(wrappedEmitter.GetMessages()) }).Should(BeNumerically(">=", 2))

			loggedText := string(logWriter.Bytes())
			expectedText := "fake error"
			Expect(loggedText).To(ContainSubstring(expectedText))
			hbEmitter.Close()
		})
	})

	Describe("Emit", func() {
		var (
			hbEmitter emitter.ByteEmitter
			testData  = []byte("hello")
		)

		BeforeEach(func() {
			hbEmitter, _ = emitter.NewHeartbeatEmitter(wrappedEmitter, origin)
		})

		It("delegates to the wrapped emitter", func() {
			hbEmitter.Emit(testData)

			messages := wrappedEmitter.GetMessages()
			Expect(messages).To(HaveLen(1))
			Expect(messages[0]).To(Equal(testData))
		})

		It("increments the heartbeat counter", func() {