Skip to content

Commit

Permalink
fix metric checking tests
Browse files Browse the repository at this point in the history
test did not actually look for only listed methods.
additionally, adds a small time buffer to alow metrics to finish being
created.
  • Loading branch information
pirtleshell committed Feb 29, 2024
1 parent bdf0d57 commit 01238ee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ var (
// search for any request metrics between startTime and time.Now() for particular request methods
// if testedmethods is empty, all metrics in timeframe are returned.
func findMetricsInWindowForMethods(db database.PostgresClient, startTime time.Time, testedmethods []string) []database.ProxiedRequestMetric {
endTime := time.Now()
// add small buffer into future in case metrics are still being created
endTime := time.Now().Add(100 * time.Millisecond)

var nextCursor int64
var proxiedRequestMetrics []database.ProxiedRequestMetric
Expand Down Expand Up @@ -151,7 +152,7 @@ func waitForMetricsInWindow(

// besides verification, waiting for the metrics ensures future tests don't fail b/c metrics are being processed
require.Eventually(t, func() bool {
metrics = findMetricsInWindowForMethods(db, startTime, []string{})
metrics = findMetricsInWindowForMethods(db, startTime, testedmethods)
return len(metrics) >= expected
}, timeout, time.Millisecond,
fmt.Sprintf("failed to find %d metrics in %f seconds from start %s", expected, timeout.Seconds(), startTime))
Expand Down

0 comments on commit 01238ee

Please sign in to comment.