This is an automated email from the ASF dual-hosted git repository.
hulee pushed a commit to branch task-improvement
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/task-improvement by this push:
new 8a9bdb2 Stabilize TestWorkflowTimeout and TestTaskRebalancer (#991)
8a9bdb2 is described below
commit 8a9bdb2dc274d94ec6a71db0fbefa32d37d3f541
Author: Ali Reza Zamani Zadeh Najari <[email protected]>
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 42d4f00..13d5d3c 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 b5af0cf..8683bea 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);
}
}