Move to latest TestNg and try to improve test retries
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/2342578f Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/2342578f Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/2342578f Branch: refs/heads/persistent-watch Commit: 2342578f424230ee9dd0abfd47f0042f9c422343 Parents: 0ad09eb Author: randgalt <randg...@apache.org> Authored: Wed Jan 11 19:52:23 2017 -0500 Committer: randgalt <randg...@apache.org> Committed: Wed Jan 11 19:52:23 2017 -0500 ---------------------------------------------------------------------- .../org/apache/curator/utils/DebugUtils.java | 1 - .../recipes/leader/TestLeaderSelector.java | 2 +- .../leader/TestLeaderSelectorParticipants.java | 2 +- .../apache/curator/test/BaseClassForTests.java | 28 ++++++-------------- pom.xml | 2 +- 5 files changed, 11 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/2342578f/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java ---------------------------------------------------------------------- diff --git a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java index b098989..ce751ec 100644 --- a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java +++ b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java @@ -23,7 +23,6 @@ public class DebugUtils public static final String PROPERTY_LOG_EVENTS = "curator-log-events"; public static final String PROPERTY_DONT_LOG_CONNECTION_ISSUES = "curator-dont-log-connection-problems"; public static final String PROPERTY_LOG_ONLY_FIRST_CONNECTION_ISSUE_AS_ERROR_LEVEL = "curator-log-only-first-connection-issue-as-error-level"; - public static final String PROPERTY_RETRY_FAILED_TESTS = "curator-retry-failed-tests"; private DebugUtils() { http://git-wip-us.apache.org/repos/asf/curator/blob/2342578f/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java index c7f415c..e072c30 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java @@ -20,6 +20,7 @@ package org.apache.curator.framework.recipes.leader; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.state.ConnectionState; @@ -32,7 +33,6 @@ import org.apache.curator.test.Timing; import org.apache.curator.utils.CloseableUtils; import org.testng.Assert; import org.testng.annotations.Test; -import org.testng.internal.annotations.Sets; import java.util.List; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; http://git-wip-us.apache.org/repos/asf/curator/blob/2342578f/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelectorParticipants.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelectorParticipants.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelectorParticipants.java index d7329ab..e026f87 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelectorParticipants.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelectorParticipants.java @@ -19,6 +19,7 @@ package org.apache.curator.framework.recipes.leader; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.apache.curator.test.BaseClassForTests; import org.apache.curator.utils.CloseableUtils; import org.apache.curator.framework.CuratorFramework; @@ -27,7 +28,6 @@ import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.retry.RetryOneTime; import org.testng.Assert; import org.testng.annotations.Test; -import org.testng.internal.annotations.Sets; import java.util.Collection; import java.util.List; import java.util.Set; http://git-wip-us.apache.org/repos/asf/curator/blob/2342578f/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java ---------------------------------------------------------------------- diff --git a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java index 13c3138..2de0099 100644 --- a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java +++ b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java @@ -27,15 +27,12 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import java.io.IOException; import java.net.BindException; -import java.util.concurrent.atomic.AtomicBoolean; public class BaseClassForTests { protected TestingServer server; - private static final int RETRY_WAIT_MS = 5000; private static final String INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES; - private static final String INTERNAL_RETRY_FAILED_TESTS; static { String logConnectionIssues = null; @@ -45,14 +42,12 @@ public class BaseClassForTests // use reflection to avoid adding a circular dependency in the pom Class<?> debugUtilsClazz = Class.forName("org.apache.curator.utils.DebugUtils"); logConnectionIssues = (String)debugUtilsClazz.getField("PROPERTY_DONT_LOG_CONNECTION_ISSUES").get(null); - retryFailedTests = (String)debugUtilsClazz.getField("PROPERTY_RETRY_FAILED_TESTS").get(null); } catch ( Exception e ) { e.printStackTrace(); } INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES = logConnectionIssues; - INTERNAL_RETRY_FAILED_TESTS = retryFailedTests; } @BeforeSuite(alwaysRun = true) @@ -105,27 +100,20 @@ public class BaseClassForTests private static class RetryTest implements IRetryAnalyzer { - private final AtomicBoolean hasBeenRetried = new AtomicBoolean(!Boolean.getBoolean(INTERNAL_RETRY_FAILED_TESTS)); + private boolean wasRetried = false; @Override public boolean retry(ITestResult result) { - boolean isRetrying = hasBeenRetried.compareAndSet(false, true); - if ( isRetrying ) + if ( result.isSuccess() || wasRetried ) { - System.err.println(String.format("Waiting " + RETRY_WAIT_MS + " ms and retrying test. Name: %s - TestName: %s ", result.getName(), result.getTestName())); - try - { - Thread.sleep(RETRY_WAIT_MS); - } - catch ( InterruptedException e ) - { - System.err.println(String.format("Retry interrupted. Name: %s - TestName: %s ", result.getName(), result.getTestName())); - Thread.currentThread().interrupt(); - isRetrying = false; - } + wasRetried = false; + return false; } - return isRetrying; + + wasRetried = true; + System.err.println(String.format("Retry test 1 time. Name: %s - TestName: %s ", result.getName(), result.getTestName())); + return true; } } http://git-wip-us.apache.org/repos/asf/curator/blob/2342578f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index fb992f0..9814b25 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ <scannotation-version>1.0.2</scannotation-version> <resteasy-jaxrs-version>2.3.0.GA</resteasy-jaxrs-version> <guava-version>16.0.1</guava-version> - <testng-version>6.8.8</testng-version> + <testng-version>6.10</testng-version> <swift-version>0.12.0</swift-version> <dropwizard-version>0.7.0</dropwizard-version> <maven-shade-plugin-version>2.3</maven-shade-plugin-version>