Skip to content

Commit 177dc52

Browse files
committed
fix: Fix test stability issues
1 parent 13cde46 commit 177dc52

24 files changed

Lines changed: 248 additions & 106 deletions

File tree

health-check/src/main/java/com/iluwatar/health/check/App.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
public class App {
4444
/** Program entry point. */
4545
public static void main(String[] args) {
46-
SpringApplication.run(App.class, args);
46+
var context = SpringApplication.run(App.class, args);
47+
if (args.length > 0 && "test".equals(args[0])) {
48+
// Close the context immediately during tests to prevent Tomcat/background threads from
49+
// hanging the JVM
50+
context.close();
51+
}
4752
}
4853
}

health-check/src/test/java/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ class AppTest {
3333
/** Entry point */
3434
@Test
3535
void shouldExecuteApplicationWithoutException() {
36-
assertDoesNotThrow(() -> App.main(new String[] {}));
36+
assertDoesNotThrow(() -> App.main(new String[] {"test"}));
3737
}
3838
}

microservices-distributed-tracing/order-microservice/src/main/java/com/iluwatar/order/microservice/Main.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public class Main {
7373
* @param args command line args
7474
*/
7575
public static void main(String[] args) {
76-
SpringApplication.run(Main.class, args);
76+
var context = SpringApplication.run(Main.class, args);
77+
if (args.length > 0 && "test".equals(args[0])) {
78+
// Close the context immediately during tests to prevent Tomcat/background threads from
79+
// hanging the JVM
80+
context.close();
81+
}
7782
}
7883
}

microservices-distributed-tracing/order-microservice/src/test/java/com/iluwatar/order/microservice/MainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
class MainTest {
3333
@Test
3434
void shouldExecuteApplicationWithoutException() {
35-
assertDoesNotThrow(() -> Main.main(new String[] {}));
35+
assertDoesNotThrow(() -> Main.main(new String[] {"test"}));
3636
}
3737
}

microservices-distributed-tracing/payment-microservice/src/main/java/com/iluwatar/payment/microservice/Main.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class Main {
7272
* @param args command line args
7373
*/
7474
public static void main(String[] args) {
75-
SpringApplication.run(Main.class, args);
75+
var context = SpringApplication.run(Main.class, args);
76+
if (args.length > 0 && "test".equals(args[0])) {
77+
// Close the context immediately during tests to prevent Tomcat/background threads from
78+
// hanging the JVM
79+
context.close();
80+
}
7681
}
7782
}

microservices-distributed-tracing/payment-microservice/src/test/java/com/iluwatar/payment/microservice/MainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
class MainTest {
3333
@Test
3434
void shouldExecuteApplicationWithoutException() {
35-
assertDoesNotThrow(() -> Main.main(new String[] {}));
35+
assertDoesNotThrow(() -> Main.main(new String[] {"test"}));
3636
}
3737
}

microservices-distributed-tracing/product-microservice/src/main/java/com/iluwatar/product/microservice/microservice/Main.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class Main {
7272
* @param args command line args
7373
*/
7474
public static void main(String[] args) {
75-
SpringApplication.run(Main.class, args);
75+
var context = SpringApplication.run(Main.class, args);
76+
if (args.length > 0 && "test".equals(args[0])) {
77+
// Close the context immediately during tests to prevent Tomcat/background threads from
78+
// hanging the JVM
79+
context.close();
80+
}
7681
}
7782
}

microservices-distributed-tracing/product-microservice/src/test/java/com/iluwatar/product/microservice/MainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
class MainTest {
3434
@Test
3535
void shouldExecuteApplicationWithoutException() {
36-
assertDoesNotThrow(() -> Main.main(new String[] {}));
36+
assertDoesNotThrow(() -> Main.main(new String[] {"test"}));
3737
}
3838
}

microservices-idempotent-consumer/src/main/java/com/iluwatar/idempotentconsumer/App.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
@Slf4j
4646
public class App {
4747
public static void main(String[] args) {
48-
SpringApplication.run(App.class, args);
48+
var context = SpringApplication.run(App.class, args);
49+
if (args.length > 0 && "test".equals(args[0])) {
50+
// Close the context immediately during tests to prevent Tomcat/background threads from
51+
// hanging the JVM
52+
context.close();
53+
}
4954
}
5055

5156
/**

microservices-idempotent-consumer/src/test/java/com/iluwatar/idempotentconsumer/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AppTest {
4040

4141
@Test
4242
void testMain() {
43-
assertDoesNotThrow(() -> App.main(new String[] {}));
43+
assertDoesNotThrow(() -> App.main(new String[] {"test"}));
4444
}
4545

4646
@Test

0 commit comments

Comments
 (0)