-
Notifications
You must be signed in to change notification settings - Fork 234
Add a couple of "stress tests" to the integration test project #11481
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
Changes from all commits
a13ac9b
72de4bd
89322e3
914ace6
e00fe0b
faba41c
c1d7007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.VisualStudio.Razor.IntegrationTests; | ||
|
|
||
| [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
| public class ManualRunOnlyIdeFactAttribute : IdeFactAttribute | ||
| { | ||
| public ManualRunOnlyIdeFactAttribute() | ||
| { | ||
| if (Environment.GetEnvironmentVariable("_IntegrationTestsRunningInCI") is not null) | ||
| { | ||
| Skip = "This test can only run manually"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Razor.Logging; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.VisualStudio.Razor.IntegrationTests; | ||
|
|
||
| [IdeSettings(MinVersion = VisualStudioVersion.VS2022, RootSuffix = "RoslynDev", MaxAttempts = 1)] | ||
| public abstract class AbstractStressTest(ITestOutputHelper testOutputHelper) : AbstractRazorEditorTest(testOutputHelper) | ||
| { | ||
| protected override bool AllowDebugFails => true; | ||
|
|
||
| protected Task RunStressTestAsync(Func<int, CancellationToken, Task> iterationFunc) | ||
| => RunStressTestAsync(iterationFunc, TimeSpan.FromHours(1), TimeSpan.FromMinutes(1)); | ||
|
|
||
| protected async Task RunStressTestAsync(Func<int, CancellationToken, Task> iterationFunc, TimeSpan maxRunTime, TimeSpan iterationTimeout) | ||
| { | ||
| var min = long.MaxValue; | ||
| var max = long.MinValue; | ||
| var avg = 0L; | ||
|
|
||
| var i = 0; | ||
| var start = DateTime.Now; | ||
| while (DateTime.Now.Subtract(maxRunTime) < start) | ||
| { | ||
| var iterationStart = Stopwatch.GetTimestamp(); | ||
| Logger.LogInformation($"**** Test iteration started: #{i} at {DateTime.Now}"); | ||
|
|
||
| using var iterationCts = new CancellationTokenSource(iterationTimeout); | ||
| var iterationToken = iterationCts.Token; | ||
|
|
||
| await iterationFunc(i, iterationToken); | ||
| i++; | ||
|
|
||
| var duration = Stopwatch.GetTimestamp() - iterationStart; | ||
| min = Math.Min(min, duration); | ||
| max = Math.Max(max, duration); | ||
| avg = ((avg * (i - 1)) + duration) / i; | ||
| Logger.LogInformation($"**** Test iteration finished: #{i} in {TimeSpan.FromTicks(duration).TotalMilliseconds}ms"); | ||
| Logger.LogInformation($"**** Test iteration duration: min={TimeSpan.FromTicks(min).TotalMilliseconds}ms, max={TimeSpan.FromTicks(max).TotalMilliseconds}ms, avg={TimeSpan.FromTicks(avg).TotalMilliseconds}ms"); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought it would be nice to get some rough timing so we can see if things get slower over time, or even compare with and without cohosting. I'm logging it every iteration because collecting logs after an hour run seems to be a little hit and miss, so didn't want to just rely on the results being the very last thing the test did. |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.WebTools.Languages.Shared.Editor.EditorHelpers; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.VisualStudio.Razor.IntegrationTests; | ||
|
|
||
| public class RCLStressTests(ITestOutputHelper testOutputHelper) : AbstractStressTest(testOutputHelper) | ||
| { | ||
| protected override string TargetFramework => "net9.0"; | ||
|
|
||
| protected override string ProjectZipFile => "Microsoft.VisualStudio.Razor.IntegrationTests.TestFiles.BlazorProjectWithRCL.zip"; | ||
|
|
||
| [ManualRunOnlyIdeFact] | ||
| public async Task AddAndRemoveComponentInRCL() | ||
| { | ||
| await TestServices.SolutionExplorer.OpenFileAsync("RazorClassLibrary", @"Components\RCLComponent.razor", ControlledHangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("<div", charsOffset: -1, ControlledHangMitigatingCancellationToken); | ||
|
|
||
| await RunStressTestAsync(RunIterationAsync); | ||
|
|
||
| async Task RunIterationAsync(int index, CancellationToken cancellationToken) | ||
| { | ||
| await TestServices.Editor.InsertTextAsync($"<h1>Iteration {index}</h1>{Environment.NewLine}", cancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("h1", charsOffset: -1, cancellationToken); | ||
|
|
||
| await TestServices.Editor.WaitForComponentClassificationAsync(cancellationToken, count: 1, exact: true); | ||
|
|
||
| await TestServices.Editor.InvokeCodeActionAsync("Extract element to new component", cancellationToken); | ||
|
|
||
| await TestServices.Editor.WaitForActiveWindowByFileAsync("Component.razor", cancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("<h1", charsOffset: -1, cancellationToken); | ||
|
|
||
| // TODO: Remove once https://github.com/dotnet/razor/issues/11478 is fixed | ||
| await TestServices.Editor.InsertTextAsync($"@namespace MyCoolNamespace{Environment.NewLine}{Environment.NewLine}", cancellationToken); | ||
|
|
||
| var componentFileName = (await TestServices.Editor.GetActiveTextViewAsync(cancellationToken)).TextBuffer.GetFileName(); | ||
|
|
||
| await TestServices.Editor.CloseCurrentlyFocusedWindowAsync(cancellationToken, save: true); | ||
|
|
||
| await TestServices.Editor.WaitForActiveWindowByFileAsync("RCLComponent.razor", cancellationToken); | ||
|
|
||
| await TestServices.Editor.WaitForComponentClassificationAsync(cancellationToken, count: 2, exact: true); | ||
|
|
||
| await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.IndexRazorFile, ControlledHangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("h1", charsOffset: -1, cancellationToken); | ||
|
|
||
| await TestServices.Editor.InvokeDeleteLineAsync(cancellationToken); | ||
|
|
||
| await TestServices.Editor.InsertTextAsync($"<Component />{Environment.NewLine}", cancellationToken); | ||
|
|
||
| await TestServices.Editor.WaitForComponentClassificationAsync(cancellationToken, count: 5, exact: true); | ||
|
|
||
| File.Delete(componentFileName); | ||
|
|
||
| await TestServices.Editor.WaitForComponentClassificationAsync(cancellationToken, count: 4, exact: true); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("<Component />", charsOffset: -1, cancellationToken); | ||
|
|
||
| await TestServices.Editor.InvokeDeleteLineAsync(cancellationToken); | ||
|
|
||
| await TestServices.Editor.InsertTextAsync($"<h1>Iteration {index}</h1>{Environment.NewLine}", cancellationToken); | ||
|
|
||
| await TestServices.SolutionExplorer.OpenFileAsync("RazorClassLibrary", @"Components\RCLComponent.razor", ControlledHangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.WaitForComponentClassificationAsync(cancellationToken, count: 1, exact: true); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("<Component />", charsOffset: -1, cancellationToken); | ||
|
|
||
| await TestServices.Editor.InvokeDeleteLineAsync(cancellationToken); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is how it was before, but why are we enumerating for just one? Or is this to assert that there is ONLY one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method did two things: Find the one "main" project we're using and return its path, and update the project file to the right TFM.
This enumeration is just the first bit, but we now also need to enumerate all of the projects to update all of the TFMs. I could have checked for this file in the other enumeration and saved it to a local but I am especially lazy in integration tests.