Check thread count in ParallelApplicationEventsIntegrationTests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user