From 32effdba0aed3f9deb546cf58d2f6f58aea90926 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 14 Jun 2021 19:15:09 +0100 Subject: [PATCH] Try to stabilize RestarterTests.testRestart Closes gh-26900 --- .../boot/devtools/restart/RestarterTests.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java index c34d0f0579..a9cdac82e5 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,12 @@ package org.springframework.boot.devtools.restart; import java.net.URL; import java.net.URLClassLoader; +import java.time.Duration; import java.util.Collection; import java.util.Collections; import java.util.concurrent.ThreadFactory; +import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -80,10 +82,11 @@ class RestarterTests { Restarter.clearInstance(); Thread thread = new Thread(SampleApplication::main); thread.start(); - Thread.sleep(2600); - assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 0")).isGreaterThan(1); - assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 1")).isGreaterThan(1); - assertThat(CloseCountingApplicationListener.closed).isGreaterThan(0); + Awaitility.await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> { + assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 0")).isGreaterThan(1); + assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 1")).isGreaterThan(1); + assertThat(CloseCountingApplicationListener.closed).isGreaterThan(0); + }); } @Test