-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
testutil.go
33 lines (30 loc) · 1.05 KB
/
testutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022-present Datadog, Inc.
package flowaggregator
import (
"fmt"
"time"
)
// WaitForFlowsToBeFlushed waits up to timeoutDuration for at least minEvents
// flows to be flushed by the aggregator. It is intended for testing.
func WaitForFlowsToBeFlushed(aggregator *FlowAggregator, timeoutDuration time.Duration, minEvents uint64) (uint64, error) {
timeout := time.After(timeoutDuration)
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
return 0, fmt.Errorf("timeout error waiting for events")
// Got a tick, we should check on doSomething()
case <-ticker.C:
events := aggregator.flushedFlowCount.Load()
if events >= minEvents {
return events, nil
}
}
}
}