Skip to content

Commit

Permalink
GEODE-8071: Prevent Test Flakiness (apache#5676)
Browse files Browse the repository at this point in the history
Different versions of the embedded Jetty server can launch non-daemon
threads, so the fix implies preventing any flakiness by just checking
for the thread we're interested in.
  • Loading branch information
jujoramos authored Oct 27, 2020
1 parent d9c859b commit 38ed638
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,18 @@ public void testRebalanceResultOutputMemberCount() {

/**
* See GEODE-8071.
* The test asserts that the amount of non-daemon threads on the locator VM remains constant
* before and after executing the re-balance command.
* The test simply asserts that the re-balance command doesn't launch a non daemon thread
* during its execution.
*/
@Test
public void rebalanceCommandShouldNotLaunchNonDaemonThreads() {
long nonDaemonThreadsBeforeCommand = locator.invoke(() -> Thread.getAllStackTraces()
.keySet()
.stream()
.filter(thread -> !thread.isDaemon())
.count());

gfsh.executeAndAssertThat("rebalance").statusIsSuccess();

long daemonThreadsAfterCommand = locator.invoke(() -> Thread.getAllStackTraces()
.keySet()
.stream()
.filter(thread -> !thread.isDaemon())
.count());

assertThat(daemonThreadsAfterCommand).isEqualTo(nonDaemonThreadsBeforeCommand);
locator.invoke(() -> {
assertThat(Thread.getAllStackTraces().keySet().stream()
.anyMatch(thread -> !thread.isDaemon()
&& thread.getName().contains(RebalanceCommand.THREAD_NAME)))
.as("Rebalance Command should not launch non daemon threads")
.isFalse();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;

import org.apache.geode.annotations.VisibleForTesting;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.logging.internal.executors.LoggingExecutors;
import org.apache.geode.management.cli.CliMetaData;
Expand All @@ -46,6 +47,9 @@
import org.apache.geode.security.ResourcePermission;

public class RebalanceCommand extends GfshCommand {
@VisibleForTesting
public static String THREAD_NAME = "RebalanceCommand";

@CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION})
@ResourceOperation(resource = ResourcePermission.Resource.DATA,
Expand All @@ -62,7 +66,7 @@ public ResultModel rebalance(
help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {

ExecutorService commandExecutors =
LoggingExecutors.newSingleThreadExecutor("RebalanceCommand", true);
LoggingExecutors.newSingleThreadExecutor(THREAD_NAME, true);
List<Future<ResultModel>> commandResult = new ArrayList<>();
ResultModel result;
try {
Expand Down

0 comments on commit 38ed638

Please sign in to comment.