Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout on regex test #63529

Merged
merged 1 commit into from
Jan 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1385,26 +1385,25 @@ private void DifficultForBacktracking(string pattern, string input, int matchcou
/// </summary>
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Doesn't support NonBacktracking")]
[Theory]
[InlineData(RegexOptions.None, 1)]
[InlineData(RegexOptions.Compiled, 1)]
public void TerminationInNonBacktrackingVsBackTracking(RegexOptions options, int sec)
[InlineData(RegexOptions.None)]
[InlineData(RegexOptions.Compiled)]
public void TerminationInNonBacktrackingVsBackTracking(RegexOptions options)
{
string input = " 123456789 123456789 123456789 123456789 123456789";
TimeSpan ts = new TimeSpan(0, 0, sec);
for (int i = 0; i < 12; i++)
{
input += input;
}

// The input has 2^12 * 50 = 204800 characters
string rawregex = @"[\\/]?[^\\/]*?(heythere|hej)[^\\/]*?$";
Regex reC = new Regex(rawregex, options, ts);
Regex re = new Regex(rawregex, RegexHelpers.RegexOptionNonBacktracking, ts);

// It takes over 4min with backtracking, so test that 1sec timeout happens
// It takes over 4min with backtracking, so it should certainly timeout given a 1 second timeout
Regex reC = new Regex(rawregex, options, TimeSpan.FromSeconds(1));
Assert.Throws<RegexMatchTimeoutException>(() => { reC.Match(input); });

// NonBacktracking needs way less than 1s
// NonBacktracking needs way less than 1s, but use 10s to account for the slowest possible CI machine
Regex re = new Regex(rawregex, RegexHelpers.RegexOptionNonBacktracking, TimeSpan.FromSeconds(10));
Assert.False(re.Match(input).Success);
}

Expand Down