From 64408433588b79dbabb9421c09aa84e11bb849ec Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 4 May 2021 09:44:56 +0100 Subject: [PATCH] Do not wait indefinitely in initialize test if refresh fails Closes gh-26286 --- .../OnInitializedRestarterConditionTests.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/OnInitializedRestarterConditionTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/OnInitializedRestarterConditionTests.java index 7fbf3383c4..c519b4dbda 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/OnInitializedRestarterConditionTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/OnInitializedRestarterConditionTests.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. @@ -39,8 +39,6 @@ import static org.mockito.Mockito.mock; */ class OnInitializedRestarterConditionTests { - private static Object wait = new Object(); - @BeforeEach @AfterEach void cleanup() { @@ -67,9 +65,8 @@ class OnInitializedRestarterConditionTests { void initialized() throws Exception { Thread thread = new Thread(TestInitialized::main); thread.start(); - synchronized (wait) { - wait.wait(); - } + thread.join(30000); + assertThat(thread.isAlive()).isFalse(); } static class TestInitialized { @@ -81,9 +78,6 @@ class OnInitializedRestarterConditionTests { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class); assertThat(context.containsBean("bean")).isTrue(); context.close(); - synchronized (wait) { - wait.notify(); - } } }