From ea16c22c6b725367e499b31054497246b67ca703 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 11 Oct 2013 14:29:15 +0000
Subject: [PATCH] Trying to fix random failures for HistoricalTest.testRecurringPurgeIn1Run().

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
index 6c0827f..fb52c58 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
@@ -721,10 +721,10 @@
     return new ReplSessionSecurity(null, null, null, true);
   }
 
-  protected void executeTask(Entry taskEntry) throws Exception
+  protected void executeTask(Entry taskEntry, long maxWaitTimeInMillis) throws Exception
   {
     addTask(taskEntry, ResultCode.SUCCESS, null);
-    waitTaskState(taskEntry, TaskState.COMPLETED_SUCCESSFULLY, null);
+    waitTaskState(taskEntry, TaskState.COMPLETED_SUCCESSFULLY, maxWaitTimeInMillis, null);
   }
 
   /**
@@ -757,7 +757,7 @@
     }
     else
     {
-      waitTaskState(taskEntry, TaskState.RUNNING, null);
+      waitTaskState(taskEntry, TaskState.RUNNING, 20000, null);
     }
 
     // Entry will be removed at the end of the test
@@ -767,13 +767,13 @@
   }
 
   protected void waitTaskState(Entry taskEntry, TaskState expectedTaskState,
-      Message expectedMessage) throws Exception
+      long maxWaitTimeInMillis, Message expectedMessage) throws Exception
   {
-    TaskState taskState = null;
-    int cpt=40;
+    long startTime = System.currentTimeMillis();
 
     SearchFilter filter = SearchFilter.createFilterFromString("(objectclass=*)");
     Entry resultEntry = null;
+    TaskState taskState = null;
     do
     {
       InternalSearchOperation searchOperation =
@@ -786,13 +786,12 @@
       String stateString = resultEntry.getAttributeValue(taskStateType, DECODER);
       taskState = TaskState.fromString(stateString);
 
-      Thread.sleep(500);
-      cpt--;
+      Thread.sleep(100);
     }
     while (taskState != expectedTaskState
         && taskState != TaskState.STOPPED_BY_ERROR
         && taskState != TaskState.COMPLETED_SUCCESSFULLY
-        && cpt > 0);
+        && (System.currentTimeMillis() - startTime < maxWaitTimeInMillis));
 
     // Check that the task contains some log messages.
     AttributeType logMessagesType =

--
Gitblit v1.10.0