Copilot commented on code in PR #6377:
URL: https://github.com/apache/shenyu/pull/6377#discussion_r3377861345
##########
shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/SentinelPluginTest.java:
##########
@@ -84,18 +90,48 @@ public void testFallbackUri() throws IOException,
ExecutionException, Interrupte
Type returnType = new TypeToken<Map<String, Object>>() {
}.getType();
- Future<Map<String, Object>> first = this.getService().submit(() ->
HttpHelper.INSTANCE.postGateway(TEST_SENTINEL_PATH, returnType));
- Future<Map<String, Object>> second = this.getService().submit(() ->
HttpHelper.INSTANCE.postGateway(TEST_SENTINEL_PATH, returnType));
- Map<String, Object> firstResult = first.get();
- Map<String, Object> secondResult = second.get();
- Set<String> messages = toMessages(firstResult, secondResult);
- Set<Integer> codes = toCodes(firstResult, secondResult);
+ List<Map<String, Object>> results = collectResultsUntil(returnType,
"pass", ShenyuResultEnum.SENTINEL_PLUGIN_FALLBACK.getMsg());
+ Set<String> messages = toMessages(results);
+ Set<Integer> codes = toCodes(results);
assertThat(messages.contains("pass"), is(true));
assertThat(codes.contains(ShenyuResultEnum.SENTINEL_PLUGIN_FALLBACK.getCode()),
is(true));
assertThat(messages.contains(ShenyuResultEnum.SENTINEL_PLUGIN_FALLBACK.getMsg()),
is(true));
}
- private static Set<String> toMessages(final Map<String, Object>...
results) {
+ private List<Map<String, Object>> collectResultsUntil(final Type
returnType,
+ final String...
expectedMessages)
+ throws ExecutionException, InterruptedException {
+ List<Map<String, Object>> results = new ArrayList<>();
+ Set<String> expected = new HashSet<>(Arrays.asList(expectedMessages));
+ for (int attempt = 0; attempt < SENTINEL_REQUEST_ATTEMPTS; attempt++) {
+ results.addAll(postSentinelRequestBurst(returnType));
+ if (toMessages(results).containsAll(expected)) {
+ return results;
+ }
+ Thread.sleep(SENTINEL_REQUEST_ATTEMPT_INTERVAL_MILLIS);
Review Comment:
`collectResultsUntil` sleeps after every attempt, including the final
attempt. This adds unnecessary delay in the failure path and makes the test
slower without improving stability. Only sleep when another retry will actually
occur.
--
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]