package metricbatcher_test

import (
	"time"

	"github.com/cloudfoundry/dropsonde/metric_sender/fake"
	"github.com/cloudfoundry/dropsonde/metricbatcher"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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")
Beispiel #2
0
package metricbatcher_test

import (
	"github.com/cloudfoundry/dropsonde/metricbatcher"

	"time"

	"github.com/cloudfoundry/dropsonde/metrics"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Deadlock", func() {
	var (
		metricBatcher *metricbatcher.MetricBatcher
		done          chan struct{}
	)

	BeforeEach(func() {
		done = make(chan struct{})

		metricSender := NewFakeMetricSender(&done)
		metricBatcher = metricbatcher.New(metricSender, 50*time.Millisecond)
		metrics.Initialize(metricSender, metricBatcher)
	})

	It("doesn't deadlock when Batch functions are called while batch sending", func() {
		metricBatcher.BatchAddCounter("count1", 2)
		Eventually(done).Should(BeClosed())
	}, 1)
})