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
This commit is contained in:
parent
8b49f792cb
commit
b9516bc77c
|
@ -546,6 +546,11 @@
|
||||||
<artifactId>aspectjrt</artifactId>
|
<artifactId>aspectjrt</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.awaitility</groupId>
|
||||||
|
<artifactId>awaitility</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-webapp</artifactId>
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.metrics.test;
|
package org.springframework.boot.actuate.autoconfigure.metrics.test;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -71,6 +72,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.awaitility.Awaitility.waitAtMost;
|
||||||
import static org.springframework.test.web.client.ExpectedCount.once;
|
import static org.springframework.test.web.client.ExpectedCount.once;
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||||
|
@ -110,7 +112,9 @@ class MetricsIntegrationTests {
|
||||||
@Test
|
@Test
|
||||||
void requestMappingIsInstrumented() {
|
void requestMappingIsInstrumented() {
|
||||||
this.loopback.getForObject("/api/people", Set.class);
|
this.loopback.getForObject("/api/people", Set.class);
|
||||||
assertThat(this.registry.get("http.server.requests").timer().count()).isEqualTo(1);
|
waitAtMost(Duration.ofSeconds(5)).untilAsserted(
|
||||||
|
() -> assertThat(this.registry.get("http.server.requests").timer().count()).isEqualTo(1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue