Skip to content

Commit

Permalink
Improve test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Nov 13, 2024
1 parent 323ba29 commit e579dac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public void assertCountPointsAtLeast(final String name, final String target, fin
.untilAsserted(() -> {
List<MetricData> metricData = getFinishedMetricItems(name, target);
Assertions.assertTrue(1 <= metricData.size());
Assertions.assertTrue(countPoints <= metricData.get(0).getData().getPoints().size());
Assertions.assertTrue(countPoints <= metricData.stream()
.reduce((first, second) -> second) // get the last received
.orElse(null)
.getData()
.getPoints()
.size());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,21 @@ private Metric getMetric(final String metricName) {
.atMost(Duration.ofSeconds(30))
.untilAsserted(() -> {
List<ExportMetricsServiceRequest> reqs = metrics.getMetricRequests();
assertThat(reqs).hasSizeGreaterThan(1);
Optional<Metric> metric = getMetric(metricName, reqs);
assertThat(metric).isPresent();
});

final List<ExportMetricsServiceRequest> metricRequests = metrics.getMetricRequests();
return getMetric(metricName, metricRequests).get();
}

private Optional<Metric> getMetric(String metricName, List<ExportMetricsServiceRequest> metricRequests) {
return metricRequests.stream()
.flatMap(reqs -> reqs.getResourceMetricsList().stream())
.flatMap(resourceMetrics -> resourceMetrics.getScopeMetricsList().stream())
.flatMap(libraryMetrics -> libraryMetrics.getMetricsList().stream())
.filter(metric -> metric.getName().equals(metricName))
.findFirst().get();
.findFirst();
}

private void verifyLogs() {
Expand Down

0 comments on commit e579dac

Please sign in to comment.