BeforeEach(func() {
		mockWriter = &mocks.MockEnvelopeWriter{}
		messageAggregator = messageaggregator.New(
			mockWriter,
			loggertesthelper.Logger(),
		)
		originalTTL = messageaggregator.MaxTTL
	})

	AfterEach(func() {
		messageaggregator.MaxTTL = originalTTL
	})

	It("passes value messages through", func() {
		inputMessage := createValueMessage()
		messageAggregator.Write(inputMessage)

		Expect(mockWriter.Events).To(HaveLen(1))
		Expect(mockWriter.Events[0]).To(Equal(inputMessage))
	})

	It("handles concurrent writes without data race", func() {
		inputMessage := createValueMessage()
		done := make(chan struct{})
		go func() {
			defer close(done)
			for i := 0; i < 100; i++ {
				messageAggregator.Write(inputMessage)
			}
		}()
		for i := 0; i < 100; i++ {
		originalTTL       time.Duration
	)

	BeforeEach(func() {
		mockWriter = &mocks.MockEnvelopeWriter{}
		messageAggregator = messageaggregator.New(mockWriter, loggertesthelper.Logger())
		originalTTL = messageaggregator.MaxTTL
	})

	AfterEach(func() {
		messageaggregator.MaxTTL = originalTTL
	})

	It("passes non-marshallable messages through", func() {
		inputMessage := &events.Envelope{}
		messageAggregator.Write(inputMessage)

		Expect(mockWriter.Events).To(HaveLen(1))
		Expect(mockWriter.Events[0]).To(Equal(inputMessage))
	})

	It("passes value messages through", func() {
		inputMessage := createValueMessage()
		messageAggregator.Write(inputMessage)

		Expect(mockWriter.Events).To(HaveLen(1))
		Expect(mockWriter.Events[0]).To(Equal(inputMessage))
	})

	Describe("counter processing", func() {
		It("sets the Total field on a CounterEvent ", func() {