Exemplo n.º 1
0
func TestNoSourcesReplyInTime(t *testing.T) {
	metricsSourceProvider := util.NewDummyMetricsSourceProvider(
		util.NewDummyMetricsSource("s1", 30*time.Second),
		util.NewDummyMetricsSource("s2", 30*time.Second))

	manager, _ := NewSourceManager(metricsSourceProvider, time.Second*3)
	now := time.Now()
	end := now.Truncate(10 * time.Second)
	dataBatch := manager.ScrapeMetrics(end.Add(-10*time.Second), end)
	elapsed := time.Now().Sub(now)

	if elapsed > 4*time.Second {
		t.Fatalf("ScrapeMetrics took too long: %s", elapsed)
	}

	if elapsed < 2*time.Second {
		t.Fatalf("ScrapeMetrics took too short: %s", elapsed)
	}

	present := make(map[string]bool)
	for key := range dataBatch.MetricSets {
		present[key] = true
	}

	if _, ok := present["s1"]; ok {
		t.Fatal("s1 found")
	}

	if _, ok := present["s2"]; ok {
		t.Fatal("s2 found")
	}
}
Exemplo n.º 2
0
func TestThrottling(t *testing.T) {
	source := util.NewDummyMetricsSource("src", time.Millisecond)
	sink := util.NewDummySink("sink", 4*time.Second)
	processor := util.NewDummyDataProcessor(5 * time.Millisecond)

	manager, _ := NewManager(source, []core.DataProcessor{processor}, sink, time.Second, time.Millisecond, 1)
	manager.Start()

	// 4-5 cycles
	time.Sleep(time.Millisecond * 9500)
	manager.Stop()

	if sink.GetExportCount() < 2 || sink.GetExportCount() > 3 {
		t.Fatalf("Wrong number of exports executed: %d", sink.GetExportCount())
	}
}