-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handful of unit test issues and the intermittent IndexOutOfRangeE…
…xception failures (#10635) It's probably easiest to go through this commit-by-commit. The main fix here is the `IndexOutOfRangeException` in the `FilePathNormalizer`. The problem occurs when the array rented from the pool already contains a `\` or `/` immediately after the span that we care about. It was possible for `FilePathNormalizer.NormalizeAndDedupeSlashes(...)` to read past the end of the span, and if it found a `\` or `/` there, it would cause the incorrect length to be used later, causing an `IndexOutOfRangeException`. The reason the failure was intermittent is because it's dependent on the contents of the array pool.
- Loading branch information
Showing
9 changed files
with
77 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
29 changes: 29 additions & 0 deletions
29
src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestMocks.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Threading; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Moq; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Test.Common; | ||
|
||
internal static class TestMocks | ||
{ | ||
public static TextLoader CreateTextLoader(string filePath, string text) | ||
{ | ||
return CreateTextLoader(filePath, SourceText.From(text)); | ||
} | ||
|
||
public static TextLoader CreateTextLoader(string filePath, SourceText text) | ||
{ | ||
var mock = new StrictMock<TextLoader>(); | ||
|
||
var textAndVersion = TextAndVersion.Create(text, VersionStamp.Create(), filePath); | ||
|
||
mock.Setup(x => x.LoadTextAndVersionAsync(It.IsAny<LoadTextOptions>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(textAndVersion); | ||
|
||
return mock.Object; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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