|
34 | 34 | import org.junit.jupiter.api.Test; |
35 | 35 | import org.junit.jupiter.api.Timeout; |
36 | 36 |
|
| 37 | +import software.amazon.lambda.powertools.testutils.DataNotReadyException; |
37 | 38 | import software.amazon.lambda.powertools.testutils.Infrastructure; |
| 39 | +import software.amazon.lambda.powertools.testutils.RetryUtils; |
38 | 40 | import software.amazon.lambda.powertools.testutils.lambda.InvocationResult; |
39 | 41 | import software.amazon.lambda.powertools.testutils.metrics.MetricsFetcher; |
40 | 42 |
|
@@ -89,16 +91,20 @@ void test_recordMetrics() { |
89 | 91 | { "FunctionName", functionName }, |
90 | 92 | { "Service", SERVICE } }).collect(Collectors.toMap(data -> data[0], data -> data[1]))); |
91 | 93 | assertThat(coldStart.get(0)).isEqualTo(1); |
92 | | - List<Double> orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), |
93 | | - 60, NAMESPACE, |
94 | | - "orders", Collections.singletonMap("Environment", "test")); |
| 94 | + List<Double> orderMetrics = RetryUtils.withRetry(() -> { |
| 95 | + List<Double> metrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), |
| 96 | + 60, NAMESPACE, "orders", Collections.singletonMap("Environment", "test")); |
| 97 | + if (metrics.get(0) != 2.0) { |
| 98 | + throw new DataNotReadyException("Expected 2.0 orders but got " + metrics.get(0)); |
| 99 | + } |
| 100 | + return metrics; |
| 101 | + }, "orderMetricsRetry", DataNotReadyException.class).get(); |
95 | 102 | assertThat(orderMetrics.get(0)).isEqualTo(2); |
96 | 103 | List<Double> productMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), |
97 | 104 | invocationResult.getEnd(), 60, NAMESPACE, |
98 | 105 | "products", Collections.singletonMap("Environment", "test")); |
99 | 106 |
|
100 | 107 | // When searching across a 1 minute time period with a period of 60 we find both metrics and the sum is 12 |
101 | | - |
102 | 108 | assertThat(productMetrics.get(0)).isEqualTo(12); |
103 | 109 |
|
104 | 110 | orderMetrics = metricsFetcher.fetchMetrics(invocationResult.getStart(), invocationResult.getEnd(), 60, |
|
0 commit comments