This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch graphql-ws-scheduler-shutdown
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 07ffe7f2d06c11a42b5646cd0a589610a7285c68
Author: Serge Huber <[email protected]>
AuthorDate: Fri Sep 4 17:32:39 2026 +0200

    Cover the destroy() wiring that stops the WebSocket deadline scheduler
    
    The factory test only showed that shutdown() stops the executor; it would
    still pass with the destroy() call removed, which is the wiring that was
    broken. Add a servlet test that configures the servlet, destroys it and 
checks
    the creator was shut down.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
 .../unomi/graphql/servlet/GraphQLServlet.java       |  5 +++++
 .../websocket/SubscriptionWebSocketFactory.java     |  3 ++-
 .../unomi/graphql/servlet/GraphQLServletTest.java   | 21 +++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
index 307a93baf..e4b3f88a8 100644
--- 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
+++ 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
@@ -110,6 +110,11 @@ public class GraphQLServlet extends WebSocketServlet {
 
     private SubscriptionWebSocketFactory socketCreator;
 
+    /** For tests: the creator whose scheduler {@link #destroy()} must stop. */
+    SubscriptionWebSocketFactory socketCreator() {
+        return socketCreator;
+    }
+
     @Override
     public void destroy() {
         try {
diff --git 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/websocket/SubscriptionWebSocketFactory.java
 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/websocket/SubscriptionWebSocketFactory.java
index 3ce1c4589..9dc5cc848 100644
--- 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/websocket/SubscriptionWebSocketFactory.java
+++ 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/websocket/SubscriptionWebSocketFactory.java
@@ -82,7 +82,8 @@ public class SubscriptionWebSocketFactory extends 
WebSocketServerFactory {
         authenticationDeadlineScheduler.shutdownNow();
     }
 
-    boolean isShutdown() {
+    /** Whether {@link #shutdown()} has run; lets the servlet test verify the 
destroy() wiring. */
+    public boolean isShutdown() {
         return authenticationDeadlineScheduler.isShutdown();
     }
 }
diff --git 
a/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
 
b/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
index ce8f62904..a6dab3341 100644
--- 
a/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
+++ 
b/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
@@ -21,6 +21,8 @@ import org.apache.unomi.api.security.SecurityService;
 import org.apache.unomi.api.services.ExecutionContextManager;
 import org.apache.unomi.graphql.servlet.auth.GraphQLServletSecurityValidator;
 import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+import org.apache.unomi.graphql.schema.GraphQLSchemaUpdater;
+import org.eclipse.jetty.websocket.api.WebSocketPolicy;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -38,6 +40,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -261,4 +265,21 @@ class GraphQLServletTest {
             nonUpgradeCalled.set(true);
         }
     }
+
+    /**
+     * The creator is only ever Jetty's WebSocketCreator, never a started 
lifecycle, so its scheduler is
+     * stopped from destroy(). This pins the wiring itself, not just that 
shutdown() works in isolation.
+     */
+    @Test
+    void destroy_shutsDownTheSocketCreatorScheduler() {
+        servlet.setGraphQLSchemaUpdater(mock(GraphQLSchemaUpdater.class));
+        when(factory.getPolicy()).thenReturn(mock(WebSocketPolicy.class));
+        servlet.configure(factory);
+        assertNotNull(servlet.socketCreator());
+        assertFalse(servlet.socketCreator().isShutdown());
+
+        servlet.destroy();
+
+        assertTrue(servlet.socketCreator().isShutdown());
+    }
 }

Reply via email to