示例#1
0
func TestAllExportsInTime(t *testing.T) {
	timeout := 3 * time.Second

	sink1 := util.NewDummySink("s1", time.Second)
	sink2 := util.NewDummySink("s2", time.Second)
	manager, _ := NewEventSinkManager([]core.EventSink{sink1, sink2}, timeout, timeout)

	elapsed := doThreeBatches(manager)
	if elapsed > 2*timeout+2*time.Second {
		t.Fatalf("3xExportEvents took too long: %s", elapsed)
	}

	assert.Equal(t, 3, sink1.GetExportCount())
	assert.Equal(t, 3, sink2.GetExportCount())
}
示例#2
0
func TestStop(t *testing.T) {
	timeout := 3 * time.Second

	sink1 := util.NewDummySink("s1", 30*time.Second)
	sink2 := util.NewDummySink("s2", 30*time.Second)
	manager, _ := NewEventSinkManager([]core.EventSink{sink1, sink2}, timeout, timeout)

	now := time.Now()
	manager.Stop()
	elapsed := time.Now().Sub(now)
	if elapsed > time.Second {
		t.Fatalf("stop too long: %s", elapsed)
	}
	time.Sleep(time.Second)

	assert.Equal(t, true, sink1.IsStopped())
	assert.Equal(t, true, sink2.IsStopped())
}
示例#3
0
func TestFlow(t *testing.T) {
	batch := &core.EventBatch{
		Timestamp: time.Now(),
		Events:    []*kube_api.Event{},
	}

	source := util.NewDummySource(batch)
	sink := util.NewDummySink("sink", time.Millisecond)

	manager, _ := NewManager(source, sink, time.Second)
	manager.Start()

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

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