}
	})

	Context("client selection", func() {
		It("selects a random client", func() {
			forwarder.Write(envelope)
			Expect(clientPool.RandomClientCallCount()).To(Equal(1))
		})

		Context("when selecting a client errors", func() {
			It("an error is logged and returns", func() {
				clientPool.RandomClientReturns(nil, errors.New("boom"))
				forwarder.Write(envelope)

				Expect(loggertesthelper.TestLoggerSink.LogContents()).To(ContainSubstring("can't forward message"))
				Expect(client.SchemeCallCount()).To(Equal(0))
			})
		})
	})

	Context("udp client", func() {
		BeforeEach(func() {
			client.SchemeReturns("udp")
		})

		It("counts the number of bytes sent", func() {
			var buffer bytes.Buffer
			bytes, err := proto.Marshal(envelope)
			Expect(err).NotTo(HaveOccurred())

			client.WriteReturns(len(bytes), nil)