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

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new f08bca6d92 test(sync): verify WebSocket subscribers remain 
connection-local (#7944)
f08bca6d92 is described below

commit f08bca6d92109140abe762aa4cfc1ba760757e42
Author: redyyang <[email protected]>
AuthorDate: Fri Oct 23 11:17:34 2026 +0800

    test(sync): verify WebSocket subscribers remain connection-local (#7944)
    
    * test(sync): verify websocket subscribers stay connection-local
    
    * test(ci): align cryptor failures and wait for usable SDK routes
    
    * test(websocket): cover connection-local discovery subscriber lists
---
 .../handler/WebsocketDataHandlerTest.java          | 52 +++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/handler/WebsocketDataHandlerTest.java
 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/handler/WebsocketDataHandlerTest.java
index 403ea262af..0eb458eddf 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/handler/WebsocketDataHandlerTest.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/handler/WebsocketDataHandlerTest.java
@@ -26,6 +26,7 @@ import java.util.List;
 
 import org.apache.shenyu.common.config.ShenyuConfig;
 import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.DiscoverySyncData;
 import org.apache.shenyu.common.dto.RuleData;
 import org.apache.shenyu.common.dto.SelectorData;
 import org.apache.shenyu.plugin.base.cache.BaseDataCache;
@@ -51,7 +52,7 @@ public final class WebsocketDataHandlerTest {
     private WebsocketDataHandler websocketDataHandler;
 
     @BeforeEach
-    public void testWebsocketDataHandler() {
+    public void setUp() {
         pluginDataSubscriber = mock(PluginDataSubscriber.class);
         List<AuthDataSubscriber> authDataSubscribers = new LinkedList<>();
         List<MetaDataSubscriber> metaDataSubscribers = new LinkedList<>();
@@ -67,6 +68,55 @@ public final class WebsocketDataHandlerTest {
                 aiProxyApiKeyDataSubscribers);
     }
 
+    @Test
+    public void testConstructingAnotherHandlerDoesNotReplaceSubscribers() {
+        PluginDataSubscriber otherSubscriber = 
mock(PluginDataSubscriber.class);
+        final WebsocketDataHandler other = new 
WebsocketDataHandler(otherSubscriber, Collections.emptyList(), 
Collections.emptyList(),
+                Collections.emptyList(), Collections.emptyList(), 
Collections.emptyList());
+
+        websocketDataHandler.executor(ConfigGroupEnum.PLUGIN, getJson(), 
DataEventTypeEnum.UPDATE.name());
+        
Mockito.verify(pluginDataSubscriber).onSubscribe(Mockito.any(PluginData.class));
+        Mockito.verifyNoInteractions(otherSubscriber);
+
+        other.executor(ConfigGroupEnum.PLUGIN, getJson(), 
DataEventTypeEnum.UPDATE.name());
+        
Mockito.verify(otherSubscriber).onSubscribe(Mockito.any(PluginData.class));
+        Mockito.verifyNoMoreInteractions(pluginDataSubscriber, 
otherSubscriber);
+    }
+
+    @Test
+    public void testSnapshotUsesTheConnectionSubscriber() {
+        PluginDataSubscriber otherSubscriber = 
mock(PluginDataSubscriber.class);
+        final WebsocketDataHandler other = new 
WebsocketDataHandler(otherSubscriber, Collections.emptyList(), 
Collections.emptyList(),
+                Collections.emptyList(), Collections.emptyList(), 
Collections.emptyList());
+
+        websocketDataHandler.snapshot(ConfigGroupEnum.PLUGIN, "[]", 
"namespace-a", "namespace-a");
+        
Mockito.verify(pluginDataSubscriber).applyPluginDataSnapshot("namespace-a", 
Collections.emptyList());
+        Mockito.verifyNoInteractions(otherSubscriber);
+
+        other.snapshot(ConfigGroupEnum.PLUGIN, "[]", "namespace-b", 
"namespace-b");
+        Mockito.verify(otherSubscriber).applyPluginDataSnapshot("namespace-b", 
Collections.emptyList());
+        Mockito.verifyNoMoreInteractions(pluginDataSubscriber, 
otherSubscriber);
+    }
+
+    @Test
+    public void testDiscoverySubscriberListsAreConnectionLocal() {
+        DiscoveryUpstreamDataSubscriber firstSubscriber = 
mock(DiscoveryUpstreamDataSubscriber.class);
+        DiscoveryUpstreamDataSubscriber secondSubscriber = 
mock(DiscoveryUpstreamDataSubscriber.class);
+        final WebsocketDataHandler first = new 
WebsocketDataHandler(pluginDataSubscriber, Collections.emptyList(), 
Collections.emptyList(),
+                Collections.emptyList(), 
Collections.singletonList(firstSubscriber), Collections.emptyList());
+        final WebsocketDataHandler second = new 
WebsocketDataHandler(pluginDataSubscriber, Collections.emptyList(), 
Collections.emptyList(),
+                Collections.emptyList(), 
Collections.singletonList(secondSubscriber), Collections.emptyList());
+        String json = 
"[{\"selectorId\":\"selector-1\",\"pluginName\":\"divide\",\"namespaceId\":\"namespace-a\",\"upstreamDataList\":[]}]";
+
+        first.executor(ConfigGroupEnum.DISCOVER_UPSTREAM, json, 
DataEventTypeEnum.UPDATE.name());
+        
verify(firstSubscriber).onSubscribe(Mockito.any(DiscoverySyncData.class));
+        Mockito.verifyNoInteractions(secondSubscriber);
+
+        second.executor(ConfigGroupEnum.DISCOVER_UPSTREAM, json, 
DataEventTypeEnum.UPDATE.name());
+        
verify(secondSubscriber).onSubscribe(Mockito.any(DiscoverySyncData.class));
+        Mockito.verifyNoMoreInteractions(firstSubscriber, secondSubscriber);
+    }
+
     @Test
     public void testPluginRefreshExecutor() {
         String json = getJson();

Reply via email to