From 016502d22e0490ed8b1b4951f5e12be01c4a224c Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Mon, 03 Aug 2026 16:13:03 +0000
Subject: [PATCH] [#807] Do not drop persistent search notifications through search-phase dedup (#812)

---
 opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java b/opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java
index 506638d..7277383 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java
@@ -47,6 +47,7 @@
 import org.forgerock.util.Utils;
 import org.opends.server.TestCaseUtils;
 import org.opends.server.core.ModifyOperation;
+import org.opends.server.core.PersistentSearch;
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.internal.SearchRequest;
 import org.opends.server.protocols.ldap.LDAPControl;
@@ -557,8 +558,29 @@
       "(objectClass=*)"
     };
 
-    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 11);
-    //cancel the persisting persistent search.
-    search.cancel(new CancelRequest(true,LocalizableMessage.EMPTY));
+    try
+    {
+      assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 11);
+    }
+    finally
+    {
+      // Cancel the persistent search itself: search.cancel() only records a cancellation request
+      // for the operation, which nothing acts upon now that the thread running it is gone, so the
+      // persistent search would stay registered and keep holding the limit set above against
+      // whatever runs next in this JVM (a failing test class is rerun in it).
+      for (PersistentSearch psearch : search.getClientConnection().getPersistentSearches())
+      {
+        if (psearch.getMessageID() == search.getMessageID())
+        {
+          psearch.cancel();
+        }
+      }
+      search.cancel(new CancelRequest(true, LocalizableMessage.EMPTY));
+
+      //Restore the limit configured for the tests.
+      ModifyRequest restoreRequest = newModifyRequest("cn=config")
+          .addModification(ModificationType.REPLACE, "ds-cfg-max-psearches", "-1");
+      assertEquals(getRootConnection().processModify(restoreRequest).getResultCode(), ResultCode.SUCCESS);
+    }
   }
 }

--
Gitblit v1.10.0