Ejemplo n.º 1
0
			Expect(fakeMetricSender.GetCounter("count2")).To(BeEquivalentTo(2)) // should update counter only when time out

			metricBatcher.BatchIncrementCounter("count1")
			metricBatcher.BatchIncrementCounter("count2")
			Expect(fakeMetricSender.GetCounter("count1")).To(BeEquivalentTo(1)) // should update counter only when time out
			Expect(fakeMetricSender.GetCounter("count2")).To(BeEquivalentTo(2)) // should update counter only when time out

			time.Sleep(75 * time.Millisecond)
			Expect(fakeMetricSender.GetCounter("count1")).To(BeEquivalentTo(2)) // should update counter only when time out
			Expect(fakeMetricSender.GetCounter("count2")).To(BeEquivalentTo(3)) // should update counter only when time out
		})
	})

	Describe("BatchAddCounter", func() {
		It("batches and then sends a single metric", func() {
			metricBatcher.BatchAddCounter("count", 2)
			Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(0)) // should not increment.

			metricBatcher.BatchAddCounter("count", 2)
			metricBatcher.BatchAddCounter("count", 3)

			time.Sleep(75 * time.Millisecond)
			Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(7)) // should update counter only when time out

			metricBatcher.BatchAddCounter("count", 1)
			metricBatcher.BatchAddCounter("count", 2)
			Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(7)) // should update counter only when time out

			time.Sleep(75 * time.Millisecond)
			Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(10)) // should update counter only when time out
		})