Skip to content

Commit

Permalink
Use unique ports in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Nov 6, 2024
1 parent 6f18df2 commit d59fa95
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dotnet-watch": {
"commandName": "Project",
"commandLineArgs": "--verbose /bl:DotnetRun.binlog",
"workingDirectory": "C:\\Temp\\Aspire4\\Aspire4.AppHost",
"workingDirectory": "C:\\sdk\\artifacts\\tmp\\Debug\\BlazorWasm_Ap---8DA5F107",
"environmentVariables": {
"DOTNET_WATCH_DEBUG_SDK_DIRECTORY": "$(RepoRoot)artifacts\\bin\\redist\\$(Configuration)\\dotnet\\sdk\\$(Version)"
}
Expand Down
8 changes: 5 additions & 3 deletions test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ public async Task BlazorWasm()
var testAsset = TestAssets.CopyTestAsset("WatchBlazorWasm")
.WithSource();

App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
var port = TestOptions.GetTestPort();
App.Start(testAsset, ["--urls", "http://localhost:" + port], testFlags: TestFlags.MockBrowser);

await App.AssertWaitingForChanges();

App.AssertOutputContains(MessageDescriptor.ConfiguredToUseBrowserRefresh);
App.AssertOutputContains(MessageDescriptor.ConfiguredToLaunchBrowser);
App.AssertOutputContains("dotnet watch ⌚ Launching browser: http://localhost:5000/");
App.AssertOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}/");

var newSource = """
@page "/"
Expand All @@ -222,7 +223,8 @@ public async Task BlazorWasm_MSBuildWarning()
"""));
});

App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
var port = TestOptions.GetTestPort();
App.Start(testAsset, ["--urls", "http://localhost:" + port], testFlags: TestFlags.MockBrowser);

await App.AssertOutputLineStartsWith("dotnet watch ⚠ msbuild: [Warning] Duplicate source file");
await App.AssertWaitingForChanges();
Expand Down
5 changes: 5 additions & 0 deletions test/dotnet-watch.Tests/Utilities/TestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Microsoft.DotNet.Watcher;

internal static class TestOptions
{
private static int s_testPort = 7000;

public static int GetTestPort()
=> Interlocked.Increment(ref s_testPort);

public static readonly ProjectOptions ProjectOptions = GetProjectOptions([]);

public static EnvironmentOptions GetEnvironmentOptions(string workingDirectory = "", string muxerPath = "")
Expand Down

0 comments on commit d59fa95

Please sign in to comment.