Skip to content

Fix 6816 sign test delay - #6917

Open
yykaue wants to merge 4 commits into
apache:masterfrom
yykaue:fix-6816-sign-test-delay
Open

Fix 6816 sign test delay#6917
yykaue wants to merge 4 commits into
apache:masterfrom
yykaue:fix-6816-sign-test-delay

Conversation

@yykaue

@yykaue yykaue commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #6816

What this PR does

Explicitly initialize the sign verification delay in SignServiceVersionOneTest and SignServiceVersionTwoTest.

Previously, both test classes constructed ComposableSignService directly with new. As a result, Spring did not process its @Value field, leaving delay at the JVM default value of 0.

This could make success-expecting tests fail intermittently when timestamp creation and verification crossed a minute boundary.

This PR:

  • Uses an explicit DELAY = 5 test constant.
  • Injects the delay into manually constructed ComposableSignService instances with ReflectionTestUtils.
  • Removes the ineffective @Value fields from the test classes.
  • Adds regression tests verifying that valid signatures from one minute earlier succeed.
  • Updates overdue tests to use the same configured delay.

Tests

./mvnw -pl shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign test
Tests run: 41, Failures: 0, Errors: 0, Skipped: 0

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Fix #6816 sign test delay

Verdict: ✅ Approve

What it fixes

SignServiceVersionOneTest and SignServiceVersionTwoTest built ComposableSignService with new, so Spring never processed the service's @Value("${shenyu.sign.delay:5}")delay stayed at the JVM default 0. The tests' own @Value private int delay field was dead code (never propagated to the service), so the success-path verification window was effectively zero tolerance. When sign-timestamp creation and signatureVerify crossed a minute boundary, a valid signature was rejected as overdue → intermittent failures.

Why the fix is correct

  • ComposableSignService.delay is confirmed to exist (field private int delay, line 81, @Value("${shenyu.sign.delay:5}")); ReflectionTestUtils.setField(signService, "delay", DELAY) correctly injects 5 minutes, matching the intended production default.
  • Verification uses Math.abs(between) <= delay (ms vs delay*60_000), so a 5-minute window now actually applies in tests.
  • Removes the two ineffective @Value fields from the test classes (they were never wired in) — clean.

Test validity (verified)

normalTestWithinConfiguredDelay signs with timestamp = now - 60_000ms (1 min earlier) and expects success(). Under delay=0 this would be overdue and fail; under delay=5 it passes — so the test genuinely guards the intended behavior rather than just passing by accident. overdueTest now uses DELAY + 1 minutes and the matching error-message format. PR reports Tests run: 41, Failures: 0.

Conclusion

Correct, well-targeted test-stability fix with a meaningful regression test. Approved.

(Reviewed as part of a descending re-pass of open PRs; this PR is new since the last review cycle.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] — Sign "success" tests run with delay=0 (constructed via new, @Value unprocessed) → minute-boundary flake

2 participants