Copilot commented on code in PR #7019:
URL: https://github.com/apache/shenyu/pull/7019#discussion_r3901057577
##########
shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/cache/BaseDataCacheTest.java:
##########
@@ -181,6 +184,27 @@ public void testObtainSelectorData() throws
NoSuchFieldException, IllegalAccessE
assertEquals(Lists.newArrayList(selectorData), selectorDataList);
}
+ @Test
+ public void testSelectorDataSnapshotRemainsStableAfterDelete() {
+ BaseDataCache.getInstance().cleanSelectorData();
+ SelectorData firstSelectorData =
SelectorData.builder().id("1").pluginName(mockPluginName1).sort(1).build();
+ SelectorData secondSelectorData =
SelectorData.builder().id("2").pluginName(mockPluginName1).sort(2).build();
+ BaseDataCache.getInstance().cacheSelectData(firstSelectorData);
+ BaseDataCache.getInstance().cacheSelectData(secondSelectorData);
+
+ List<SelectorData> snapshot =
BaseDataCache.getInstance().obtainSelectorData(mockPluginName1);
+ Iterator<SelectorData> iterator = snapshot.iterator();
+ assertEquals(firstSelectorData, iterator.next());
+
+ BaseDataCache.getInstance().removeSelectData(firstSelectorData);
+
+ assertDoesNotThrow(() -> iterator.forEachRemaining(selector ->
assertNotNull(selector)));
+ assertEquals(Lists.newArrayList(firstSelectorData,
secondSelectorData), snapshot);
+ assertEquals(Lists.newArrayList(secondSelectorData),
BaseDataCache.getInstance().obtainSelectorData(mockPluginName1));
+ assertThrows(UnsupportedOperationException.class, () ->
snapshot.add(firstSelectorData));
+ BaseDataCache.getInstance().cleanSelectorData();
+ }
Review Comment:
This test mutates singleton BaseDataCache state and relies on the final
cleanSelectorData() call to avoid leaking state into other tests, but the
cleanup is not in a finally block. If an assertion fails earlier, cache state
can leak and cause order-dependent/flaky tests.
This issue also appears on line 283 of the same file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]