Copilot commented on code in PR #7049:
URL: https://github.com/apache/shenyu/pull/7049#discussion_r4032629886


##########
shenyu-plugin/shenyu-plugin-mock/src/test/java/org/apache/shenyu/plugin/mock/generator/ExpressionGeneratorTest.java:
##########
@@ -182,6 +188,47 @@ public void testGenerateDataFromReq() {
         assertThat(generator.generate("expression|#req.json.address.country", 
mockRequest),
                 is("\"CHINA\""));
     }
+
+    @Test
+    public void testGenerateDataFromReqConcurrently() throws Exception {
+        ExecutorService executor = Executors.newFixedThreadPool(2);
+        try {
+            assertConcurrentRequestValues(executor, generator, 
"expression|#req.json.value");
+            assertConcurrentRequestValues(executor, new 
StandardExpressionGenerator(), "standardSPELExpression|#req.json.value");
+        } finally {
+            executor.shutdownNow();
+            executor.awaitTermination(5, TimeUnit.SECONDS);
+        }
+    }
+
+    private void assertConcurrentRequestValues(final ExecutorService executor, 
final Generator<String> testGenerator,
+                                               final String rule) throws 
Exception {
+        for (int i = 0; i < 100; i++) {
+            MockRequest firstRequest = createRequest("first");
+            MockRequest secondRequest = createRequest("second");
+            CyclicBarrier barrier = new CyclicBarrier(2);

Review Comment:
   The barrier only synchronizes both tasks before entering `generate`; it does 
not force either task to run after the other task has executed 
`context.setVariable("req", ...)` and before its `getValue(...)`. With the old 
shared-context implementation, both tasks can complete their set/read pair 
sequentially, so this test can pass all 100 iterations despite the regression. 
Please make the interleaving deterministic (for example, expose/inject a test 
hook around context setup or otherwise coordinate between setup and evaluation) 
rather than relying on scheduler timing.



-- 
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]

Reply via email to