) var _ = Describe("MetricBatcher", func() { var ( fakeMetricSender *fake.FakeMetricSender metricBatcher *metricbatcher.MetricBatcher ) BeforeEach(func() { fakeMetricSender = fake.NewFakeMetricSender() metricBatcher = metricbatcher.New(fakeMetricSender, 50*time.Millisecond) }) Describe("BatchIncrementCounter", func() { It("batches and then sends a single metric", func() { metricBatcher.BatchIncrementCounter("count") Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(0)) // should not increment. metricBatcher.BatchIncrementCounter("count") metricBatcher.BatchIncrementCounter("count") time.Sleep(75 * time.Millisecond) Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(3)) // should update counter only when time out metricBatcher.BatchIncrementCounter("count") metricBatcher.BatchIncrementCounter("count") Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(3)) // should update counter only when time out time.Sleep(75 * time.Millisecond) Expect(fakeMetricSender.GetCounter("count")).To(BeEquivalentTo(5)) // should update counter only when time out })