From 1e618c36a00896d7250439caba2f5c96e7bfb301 Mon Sep 17 00:00:00 2001 From: Robert Pirtle Date: Thu, 29 Feb 2024 13:19:35 -0800 Subject: [PATCH] fix metric checking tests test did not actually look for only listed methods. additionally, adds a small time buffer to alow metrics to finish being created. --- main_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main_test.go b/main_test.go index d0d2167..f038272 100644 --- a/main_test.go +++ b/main_test.go @@ -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 @@ -112,8 +113,10 @@ func findMetricsInWindowForMethods(db database.PostgresClient, startTime time.Ti // iterate in reverse order to start checking the most recent request metrics first for i := len(proxiedRequestMetrics) - 1; i >= 0; i-- { requestMetric := proxiedRequestMetrics[i] + fmt.Printf("%+v", requestMetric) isBetween := requestMetric.RequestTime.After(startTime) && requestMetric.RequestTime.Before(endTime) if isBetween || requestMetric.RequestTime.Equal(startTime) || requestMetric.RequestTime.Equal(endTime) { + fmt.Println(" is within timeframe!") // collect all metrics if testedmethods = [] if len(testedmethods) == 0 { requestMetricsDuringRequestWindow = append(requestMetricsDuringRequestWindow, requestMetric) @@ -125,6 +128,8 @@ func findMetricsInWindowForMethods(db database.PostgresClient, startTime time.Ti requestMetricsDuringRequestWindow = append(requestMetricsDuringRequestWindow, requestMetric) } } + } else { + fmt.Println(" - NOPE") } } @@ -151,7 +156,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))