You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/09/09 07:22:35 UTC
[pulsar] 04/07: [Tests] Use TestRetrySupport for
BaseMetadataStoreTests to cleanup state between retries (#11771)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit e4cdfe574516eb7d82b2130df022fcbc83521dfe
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Wed Aug 25 11:22:13 2021 +0300
[Tests] Use TestRetrySupport for BaseMetadataStoreTests to cleanup state between retries (#11771)
* [Tests] Use TestRetrySupport for BaseMetadataStoreTests to cleanup state between retries
- mitigates flaky tests in LockManagerTest #11690 and ZkSessionTest #11032
* [Tests] Add notes about the correct usage of TestRetrySupport
(cherry picked from commit 7de9992b6c047fbdda7ab47ba83b97156f881d12)
---
.../java/org/apache/pulsar/tests/TestRetrySupport.java | 17 +++++++++++++++++
.../apache/pulsar/metadata/BaseMetadataStoreTest.java | 13 ++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/buildtools/src/main/java/org/apache/pulsar/tests/TestRetrySupport.java b/buildtools/src/main/java/org/apache/pulsar/tests/TestRetrySupport.java
index c4b9fc6..a9bf4b4 100644
--- a/buildtools/src/main/java/org/apache/pulsar/tests/TestRetrySupport.java
+++ b/buildtools/src/main/java/org/apache/pulsar/tests/TestRetrySupport.java
@@ -33,6 +33,10 @@ import org.testng.annotations.BeforeMethod;
* This is useful for making test retries to work on classes which use BeforeClass
* and AfterClass methods to setup a test environment that is shared across all test methods in the test
* class.
+ *
+ * The setup method implementation must call incrementSetupNumber method and the cleanup method must call
+ * markCurrentSetupNumberCleaned method. This is required by the state tracking logic.
+ *
*/
public abstract class TestRetrySupport {
private static final Logger LOG = LoggerFactory.getLogger(TestRetrySupport.class);
@@ -83,12 +87,25 @@ public abstract class TestRetrySupport {
LOG.debug("currentSetupNumber={}", currentSetupNumber);
}
+ /**
+ * This method should be called in the cleanup method of the concrete class.
+ */
protected final void markCurrentSetupNumberCleaned() {
cleanedUpSetupNumber = currentSetupNumber;
LOG.debug("cleanedUpSetupNumber={}", cleanedUpSetupNumber);
}
+ /**
+ * Initializes the test environment state.
+ *
+ * The implementation of this method must call incrementSetupNumber method.
+ */
protected abstract void setup() throws Exception;
+ /**
+ * Cleans up the state of the environment.
+ *
+ * The implementation of this method must call the markCurrentSetupNumberCleaned method.
+ */
protected abstract void cleanup() throws Exception;
}
diff --git a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
index 49c916a..afd6f3a 100644
--- a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
+++ b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
@@ -19,23 +19,26 @@
package org.apache.pulsar.metadata;
import static org.testng.Assert.assertTrue;
-
import java.util.concurrent.CompletionException;
-
+import org.apache.pulsar.tests.TestRetrySupport;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
-public abstract class BaseMetadataStoreTest {
+public abstract class BaseMetadataStoreTest extends TestRetrySupport {
protected TestZKServer zks;
@BeforeClass(alwaysRun = true)
- void setup() throws Exception {
+ @Override
+ protected void setup() throws Exception {
+ incrementSetupNumber();
zks = new TestZKServer();
}
@AfterClass(alwaysRun = true)
- void teardown() throws Exception {
+ @Override
+ protected void cleanup() throws Exception {
+ markCurrentSetupNumberCleaned();
zks.close();
}