mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

coulbeck
09.13.2006 bae7bd860f5156e452d86c1667f009d63522c7d3
Tests that use the post-response plugin invocation counter are subject to race conditions.  An earlier test can complete successfully with an operation still running in the server, and this operation changes the values of the invocation counters while subsequent tests are running.

A new method InvocationCounterPlugin#waitForPostResponse can be used in a test to wait until an operation has invoked the post-response plugins, so that the operation doesn't interfere with subsequent tests.
3 files modified
28 ■■■■ changed files
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java 3 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/plugins/InvocationCounterPlugin.java 23 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
@@ -647,7 +647,7 @@
        assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
        assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
        // The post response might not have been called yet.
//        assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
        assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
      } finally
      {
        LockManager.unlock(entry.getDN(), writeLock);
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
@@ -1086,6 +1086,7 @@
        message.getModifyDNResponseProtocolOp();
    assertEquals(modifyResponse.getResultCode(), 80);
    assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
    try
    {
@@ -1145,7 +1146,7 @@
        assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
        assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
        // The post response might not have been called yet. 
//        assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
        assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
      } finally
      {
        LockManager.unlock(entry.getDN(), writeLock);
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/plugins/InvocationCounterPlugin.java
@@ -28,8 +28,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -1065,5 +1063,26 @@
  {
    shutdownCalled = false;
  }
  /**
   * Waits up to five seconds until the post-response plugins have been called
   * at least once since the last reset.
   * @return The number of times that the post-response plugins have been
   *         called since the last reset.  The return value may be zero if the
   *         wait timed out.
   * @throws InterruptedException If another thread interrupts this thread.
   */
  public static int waitForPostResponse() throws InterruptedException
  {
    long timeout = System.currentTimeMillis() + 5000;
    while (postResponseCounter.get() == 0 &&
         System.currentTimeMillis() < timeout)
    {
      Thread.sleep(10);
    }
    return postResponseCounter.get();
  }
}