From d0f0e78dc70d1e8ee436eb2332c3ae0e95a9266c Mon Sep 17 00:00:00 2001
From: davidely <davidely@localhost>
Date: Wed, 18 Apr 2007 15:43:28 +0000
Subject: [PATCH] This is a fix for race condition problems in the unit tests where operations left over from the previous test cause the following test to fail. For the affected tests, the solution was to wait for all previous operations to complete before starting the next test.
---
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java | 3 +++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java | 3 +++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java | 1 +
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java | 17 +++++++++++++++++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java | 23 +++++++++++++++++++++++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java | 9 ++++++++-
6 files changed, 55 insertions(+), 1 deletions(-)
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 9c39954..ca0f3d9 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -79,6 +79,7 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import org.opends.server.tasks.TaskUtils;
+import org.opends.server.api.WorkQueue;
/**
* This class defines some utility functions which can be used by test
@@ -316,6 +317,28 @@
}
/**
+ * Bring the server to a quiescent state. This includes waiting for all
+ * operations to complete. This can be used in a @BeforeMethod setup method
+ * to make sure that the server has finished processing all operations
+ * from previous tests.
+ */
+ public static void quiesceServer()
+ {
+ waitForOpsToComplete();
+ }
+
+ /**
+ * This can be made public if quiesceServer becomes too heavy-weight in
+ * some circumstance.
+ */
+ private static void waitForOpsToComplete()
+ {
+ WorkQueue workQueue = DirectoryServer.getWorkQueue();
+ final long NO_TIMEOUT = -1;
+ workQueue.waitUntilIdle(NO_TIMEOUT);
+ }
+
+ /**
* Binds to the given socket port on the local host.
* @return the bounded Server socket.
*
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java
index 25a6e53..03d3993 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java
@@ -34,6 +34,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
@@ -878,6 +879,7 @@
assertTrue(InvocationCounterPlugin.getPreParseCount() > 0);
assertTrue(InvocationCounterPlugin.getPreOperationCount() > 0);
assertTrue(InvocationCounterPlugin.getPostOperationCount() > 0);
+ ensurePostReponseHasRun();
assertTrue(InvocationCounterPlugin.getPostResponseCount() > 0);
}
@@ -905,6 +907,7 @@
assertTrue(InvocationCounterPlugin.getPreParseCount() > 0);
assertTrue(InvocationCounterPlugin.getPreOperationCount() > 0);
assertTrue(InvocationCounterPlugin.getPostOperationCount() > 0);
+ ensurePostReponseHasRun();
assertTrue(InvocationCounterPlugin.getPostResponseCount() > 0);
}
@@ -1941,6 +1944,10 @@
assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(),
1);
+ // We occasionally run into
+ // ProtocolMessages.MSGID_LDAP_CLIENT_DUPLICATE_MESSAGE_ID, so we wait
+ // for previous ops to complete.
+ TestCaseUtils.quiesceServer();
bindRequest = new BindRequestProtocolOp(
new ASN1OctetString("cn=Directory Manager"), 3,
new ASN1OctetString("password"));
@@ -1949,7 +1956,7 @@
message = LDAPMessage.decode(r.readElement().decodeAsSequence());
bindResponse = message.getBindResponseProtocolOp();
- assertEquals(bindResponse.getResultCode(), 0);
+ assertEquals(bindResponse.getResultCode(), 0, message.toString());
assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN));
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
index ff03eb1..13f4618 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
@@ -159,6 +159,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
@@ -179,6 +180,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
@@ -199,6 +201,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
index 23a3fc1..e50edcb 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
@@ -31,6 +31,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
import org.opends.server.TestCaseUtils;
import org.opends.server.util.StaticUtils;
@@ -56,7 +57,23 @@
// The LDAPStatistics object associated with the LDAPS connection handler.
protected LDAPStatistics ldapsStatistics;
+ @BeforeMethod
+ public void setUpQuiesceServer()
+ {
+ TestCaseUtils.quiesceServer();
+ }
+ /**
+ * Since the PostResponse plugins are called after the response is sent
+ * back to the client, a client (e.g. a test case) can get a response before
+ * the PostResponse plugins have been called. So that we can verify that the
+ * PostResponse plugins were called, the tests call this method to ensure
+ * that all operations in the server have been completed.
+ */
+ protected void ensurePostReponseHasRun()
+ {
+ TestCaseUtils.quiesceServer();
+ }
/**
* Ensures that the Directory Server is running.
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
index 56f4de7..ef8101a 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
@@ -213,6 +213,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
index 11023c5..1e1eb42 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
@@ -172,6 +172,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
@@ -192,6 +193,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
@@ -212,6 +214,7 @@
assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
+ ensurePostReponseHasRun();
assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
--
Gitblit v1.10.0