func newFakeClient(proto, addr string) *fakeclient.FakeClient {
	c := fakeclient.FakeClient{}
	c.SchemeReturns(proto)
	c.AddressReturns(addr)
	return &c
}
		})

		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("marshals, signs, writes and emits metrics", func() {
			bytes, err := proto.Marshal(envelope)
			Expect(err).NotTo(HaveOccurred())
			bytes = signature.SignMessage(bytes, sharedSecret)

			forwarder.Write(envelope)

			Expect(client.WriteArgsForCall(0)).To(Equal(bytes))
			Eventually(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(1))
			Expect(sender.GetCounter("dropsondeMarshaller.logMessageMarshalled")).To(BeEquivalentTo(1))
		})

		Context("when writes fail", func() {