You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/08/04 21:14:38 UTC
[helix] 02/10: Stabilize TestWorkflowTimeout and TestTaskRebalancer
(#991)
This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
commit f4cfbc74d8cc3a1ca03959c1301233bc014b7452
Author: Ali Reza Zamani Zadeh Najari <an...@linkedin.com>
AuthorDate: Mon May 4 14:30:43 2020 -0700
Stabilize TestWorkflowTimeout and TestTaskRebalancer (#991)
In this commit, two tests have been stabilized.
These tests are TestWorkflowTimeout and TestTaskRebalancer.
These tests are identified as unstable because they are relying on Thread.Sleep()
---
.../helix/integration/task/TestTaskRebalancer.java | 14 +++++++++-----
.../helix/integration/task/TestWorkflowTimeout.java | 17 +++++++++++------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
index 8a3c252..a09710a 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
@@ -59,7 +59,7 @@ public class TestTaskRebalancer extends TaskTestBase {
@Test
public void testExpiry() throws Exception {
String jobName = "Expiry";
- long expiry = 1000;
+ long expiry = 1000L;
Map<String, String> commandConfig = ImmutableMap.of(MockTask.JOB_DELAY, String.valueOf(100));
JobConfig.Builder jobBuilder = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG);
jobBuilder.setJobCommandConfigMap(commandConfig);
@@ -83,12 +83,16 @@ public class TestTaskRebalancer extends TaskTestBase {
// Wait for job to finish and expire
_driver.pollForWorkflowState(jobName, TaskState.COMPLETED);
- Thread.sleep(expiry + 100);
+ long finishTime = _driver.getWorkflowContext(jobName).getFinishTime();
// Ensure workflow config and context were cleaned up by now
- Assert.assertFalse(
- _manager.getHelixPropertyStore().exists(workflowPropStoreKey, AccessOption.PERSISTENT));
- Assert.assertNull(accessor.getProperty(workflowCfgKey));
+ Assert.assertTrue(TestHelper.verify(
+ () -> (!_manager.getHelixPropertyStore().exists(workflowPropStoreKey,
+ AccessOption.PERSISTENT) && accessor.getProperty(workflowCfgKey) == null),
+ TestHelper.WAIT_DURATION));
+
+ long cleanUpTime = System.currentTimeMillis();
+ Assert.assertTrue(cleanUpTime - finishTime >= expiry);
}
private void basic(long jobCompletionTime) throws Exception {
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestWorkflowTimeout.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestWorkflowTimeout.java
index 4cf07db..c79913f 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestWorkflowTimeout.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestWorkflowTimeout.java
@@ -102,18 +102,23 @@ public class TestWorkflowTimeout extends TaskTestBase {
}
@Test
- public void testWorkflowTimeoutWhenWorkflowCompleted() throws InterruptedException {
+ public void testWorkflowTimeoutWhenWorkflowCompleted() throws Exception {
String workflowName = TestHelper.getTestMethodName();
+ long expiry = 2000L;
_jobBuilder.setWorkflow(workflowName);
_jobBuilder.setJobCommandConfigMap(Collections.<String, String> emptyMap());
Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName)
.setWorkflowConfig(new WorkflowConfig.Builder(workflowName).setTimeout(0).build())
- .addJob(JOB_NAME, _jobBuilder).setExpiry(2000L);
+ .addJob(JOB_NAME, _jobBuilder).setExpiry(expiry);
+ // Since workflow's Timeout is 0, the workflow goes to TIMED_OUT state right away
+ long startTime = System.currentTimeMillis();
_driver.start(workflowBuilder.build());
- // Pause the queue
- Thread.sleep(2500);
- Assert.assertNull(_driver.getWorkflowConfig(workflowName));
- Assert.assertNull(_driver.getJobContext(workflowName));
+
+ Assert.assertTrue(TestHelper.verify(() -> (_driver.getWorkflowConfig(workflowName) == null
+ && _driver.getWorkflowContext(workflowName) == null), TestHelper.WAIT_DURATION));
+
+ long cleanUpTime = System.currentTimeMillis();
+ Assert.assertTrue(cleanUpTime - startTime >= expiry);
}
}