From cd9d562129c6bc965e1e4042628d66cd188b7ad3 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 25 Jan 2021 11:02:36 +0100 Subject: [PATCH] Check thread count in ParallelApplicationEventsIntegrationTests --- ...ParallelApplicationEventsIntegrationTests.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java index a2de1a87e4..2b3d18b682 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-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. @@ -16,6 +16,7 @@ package org.springframework.test.context.junit.jupiter.event; +import java.lang.management.ManagementFactory; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -74,10 +75,14 @@ class ParallelApplicationEventsIntegrationTests { assertThat(payloads).hasSize(10); assertThat(testNames).hasSize(10); - // There are probably 10 different thread names on a developer's machine, - // but we really just want to assert that at least two different threads - // were used, since the CI server seems to have fewer threads available. - assertThat(threadNames).hasSizeGreaterThanOrEqualTo(2); + + // Skip the following assertion entirely if the thread count is too low. + if (ManagementFactory.getThreadMXBean().getThreadCount() >= 2) { + // There are probably 10 different thread names on a developer's machine, + // but we really just want to assert that at least two different threads + // were used, since the CI server often has fewer threads available. + assertThat(threadNames).hasSizeGreaterThanOrEqualTo(2); + } }