Skip to content

Commit b9516bc

Browse files
committed
Await registration of http.server.requests meter
Previously, the test would make an HTTP request and, as soon as the response was received, it would check the presence and value of the http.server.requests meter. This create a race condition between the meter being registered once the response had been flushed and the meter's presence being checked. If the check won the race, the test would fail. This commit updates the test to wait for up to 5 seconds for the meter to be present and have a count of 1, matching the single request that has been made. Fixes gh-23919
1 parent 8b49f79 commit b9516bc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@
546546
<artifactId>aspectjrt</artifactId>
547547
<scope>test</scope>
548548
</dependency>
549+
<dependency>
550+
<groupId>org.awaitility</groupId>
551+
<artifactId>awaitility</artifactId>
552+
<scope>test</scope>
553+
</dependency>
549554
<dependency>
550555
<groupId>org.eclipse.jetty</groupId>
551556
<artifactId>jetty-webapp</artifactId>

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/test/MetricsIntegrationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.test;
1818

19+
import java.time.Duration;
1920
import java.util.Collections;
2021
import java.util.Map;
2122
import java.util.Set;
@@ -71,6 +72,7 @@
7172
import org.springframework.web.client.RestTemplate;
7273

7374
import static org.assertj.core.api.Assertions.assertThat;
75+
import static org.awaitility.Awaitility.waitAtMost;
7476
import static org.springframework.test.web.client.ExpectedCount.once;
7577
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
7678
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
@@ -110,7 +112,9 @@ void restTemplateIsInstrumented() {
110112
@Test
111113
void requestMappingIsInstrumented() {
112114
this.loopback.getForObject("/api/people", Set.class);
113-
assertThat(this.registry.get("http.server.requests").timer().count()).isEqualTo(1);
115+
waitAtMost(Duration.ofSeconds(5)).untilAsserted(
116+
() -> assertThat(this.registry.get("http.server.requests").timer().count()).isEqualTo(1));
117+
114118
}
115119

116120
@Test

0 commit comments

Comments
 (0)