return sender.GetCounter("tls.sentMessageCount")
			}).Should(BeEquivalentTo(1))
		})

		It("stream and emits metrics", func() {
			var buffer bytes.Buffer
			bytes, err := proto.Marshal(envelope)
			Expect(err).NotTo(HaveOccurred())

			n := uint32(len(bytes))
			err = binary.Write(&buffer, binary.LittleEndian, n)
			Expect(err).NotTo(HaveOccurred())

			forwarder.Write(envelope)

			Eventually(func() int { return client.WriteCallCount() }).Should(Equal(2))
			Eventually(func() []byte { return client.WriteArgsForCall(0) }).Should(Equal(buffer.Bytes()))
			Eventually(func() []byte { return client.WriteArgsForCall(1) }).Should(Equal(bytes))

			Eventually(func() uint64 { return sender.GetCounter("DopplerForwarder.sentMessages") }).Should(BeEquivalentTo(1))
			Eventually(func() uint64 { return sender.GetCounter("dropsondeMarshaller.logMessageMarshalled") }).Should(BeEquivalentTo(1))
		})

		Context("write returns an error", func() {
			BeforeEach(func() {
				client.WriteStub = func([]byte) (int, error) {
					switch client.WriteCallCount() {
					case 2:
						return 0, errors.New("write failure")
					default:
						return 0, nil
				return sender.GetCounter("tls.sendErrorCount")
			}).Should(BeEquivalentTo(1))
		})

		It("stream and emits metrics", func() {
			var buffer bytes.Buffer
			bytes, err := proto.Marshal(envelope)
			Expect(err).NotTo(HaveOccurred())

			n := uint32(len(bytes))
			err = binary.Write(&buffer, binary.LittleEndian, n)
			Expect(err).NotTo(HaveOccurred())

			forwarder.Write(envelope)

			Expect(client.WriteCallCount()).To(Equal(2))
			Expect(client.WriteArgsForCall(0)).To(Equal(buffer.Bytes()))
			Expect(client.WriteArgsForCall(1)).To(Equal(bytes))

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

		Context("with a network error", func() {
			BeforeEach(func() {
				client.WriteReturns(0, &net.OpError{Op: "dial", Err: errors.New("boom")})

				forwarder.Write(envelope)
			})

			It("closes the client", func() {