From 914b3588b032f432f4e61b9b56d99b07947d7807 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 11 Aug 2017 20:26:09 +0100 Subject: [PATCH] Update test as response may be received before server has deleted file Previously, the heap dump endpoint test asserted that the temporary heap dump file had been deleted as soon as the client received a response. This led to intermittent test failures as the input stream is closed after its contents have been sent to the client, creating a race condition between the client receiving the response and then asserting that the file had been deleted and the server close the input stream and deleting the temporary file. This commit updates the test so that, after receiving the response, it will wait for up to 5 seconds for the server to have deleted the temporary heap dump file. --- .../web/HeapDumpWebEndpointWebIntegrationTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpointWebIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpointWebIntegrationTests.java index 866bb584c4..8d88cd7dba 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpointWebIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/HeapDumpWebEndpointWebIntegrationTests.java @@ -69,6 +69,14 @@ public class HeapDumpWebEndpointWebIntegrationTests { client.get().uri("/application/heapdump").exchange().expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_OCTET_STREAM) .expectBody(String.class).isEqualTo("HEAPDUMP"); + assertHeapDumpFileIsDeleted(); + } + + private void assertHeapDumpFileIsDeleted() throws InterruptedException { + long end = System.currentTimeMillis() + 5000; + while (System.currentTimeMillis() < end && this.endpoint.file.exists()) { + Thread.sleep(100); + } assertThat(this.endpoint.file.exists()).isFalse(); }