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

Valery Kharseko
20 hours ago 6b0b8680202b4948beea72921ae5d27bd82fb50a
[#770] Fix flaky PostConnectedDisconnectTest (#771)
1 files modified
18 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/PostConnectedDisconnectTest.java 18 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/jmx/PostConnectedDisconnectTest.java
@@ -95,10 +95,8 @@
  @Test
  public void checkPostConnectDisconnectPlugin() throws Exception
  {
    // Before the test, how many time postconnect and postdisconnect
    // have been called.
    // Before the test, how many time postconnect has been called.
    int postConnectBefore = InvocationCounterPlugin.getPostConnectCount();
    int postDisconnectBefore = InvocationCounterPlugin.getPostDisconnectCount();
    // Create a new client connection
    HashMap<String, Object> env = new HashMap<>();
@@ -123,9 +121,11 @@
    }
    assertEquals(postConnectBefore +1, postConnectAfter);
    // Check that postDisconnect is not incremented.
    int postDisconnectAfter = InvocationCounterPlugin.getPostDisconnectCount();
    assertEquals(postDisconnectBefore, postDisconnectAfter);
    // Snapshot the post-disconnect counter just before closing: connections left
    // over from earlier JMX test classes are torn down asynchronously (JMX
    // CLOSED/FAILED notifications), so the counter may move at any time while
    // this test is running.
    int postDisconnectBefore = InvocationCounterPlugin.getPostDisconnectCount();
    // Close the client connection
    opendsConnector.close();
@@ -133,14 +133,16 @@
    // Check that number of postdisconnect has been incremented.
    // Don't wait more than 5 seconds
    endTime = System.currentTimeMillis() + 5000;
    postDisconnectAfter = postDisconnectBefore;
    int postDisconnectAfter = postDisconnectBefore;
    while (System.currentTimeMillis() < endTime
        && postDisconnectAfter == postDisconnectBefore)
    {
      Thread.sleep(10);
      postDisconnectAfter = InvocationCounterPlugin.getPostDisconnectCount();
    }
    assertEquals(postDisconnectBefore +1 , postDisconnectAfter);
    // Stray disconnects from earlier test classes may also be counted here, so
    // only require that at least one post-disconnect was recorded.
    assertTrue(postDisconnectAfter > postDisconnectBefore);
    // Check that postconnect is not incremented again.
    postConnectAfter = InvocationCounterPlugin.getPostConnectCount();