Fix flaky RegularExpressionAttribute timeout test#127247
Open
danmoseley wants to merge 1 commit intodotnet:mainfrom
Open
Fix flaky RegularExpressionAttribute timeout test#127247danmoseley wants to merge 1 commit intodotnet:mainfrom
danmoseley wants to merge 1 commit intodotnet:mainfrom
Conversation
The test used a 28-character input with a 1ms timeout, but regex engine improvements allowed completion before the timeout check fired, causing IsValid to return false instead of throwing RegexMatchTimeoutException. Use 100 characters to ensure the exponential backtracking exceeds the timeout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a rare CI flake in RegularExpressionAttributeTests.Validate_MatchingTimesOut_ThrowsRegexMatchTimeoutException by making the test input reliably trigger a RegexMatchTimeoutException even with recent regex engine performance improvements.
Changes:
- Increase the input length used in the timeout test from a fixed short literal to
new string('a', 100) + ">"to more consistently exceed a 1ms regex timeout.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/RegularExpressionAttributeTests.cs | Strengthens the timeout test input to reduce flakiness and keep the expected exception stable. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations |
Member
Author
|
ha, it already had to get slowed-down once |
This was referenced Apr 22, 2026
Open
adamsitnik
approved these changes
Apr 22, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, thank you @danmoseley !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix flaky RegularExpressionAttribute timeout test
Rare CI failure in
RegularExpressionAttributeTests.Validate_MatchingTimesOut_ThrowsRegexMatchTimeoutException:The test uses pattern
(a[ab]+)+$with a 1ms timeout, expecting catastrophic backtracking to cause aRegexMatchTimeoutException. The input was a hardcoded 28-character string ("aaaaaaaaaaaaaaaaaaaaaaaaaaaa>"). With regex engine improvements, the backtracking sometimes completes within the 1ms timeout window before the timeout check fires. When that happens,IsValid()returnsfalse(no match) andValidate()wraps it as aValidationExceptioninstead of the expectedRegexMatchTimeoutException.The fix increases the input length from 28 to 100 characters (
new string('a', 100) + ">"), making the exponential backtracking work (O(2^n)) large enough that the 1ms timeout is reliably exceeded.Note
This change was AI-generated with GitHub Copilot.