Skip to content
Draft
Show file tree
Hide file tree
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 @@ -61,9 +61,8 @@ internal sealed record EnvironmentOptions(
);

public TimeSpan GetProcessCleanupTimeout(bool isHotReloadEnabled)
// If Hot Reload mode is disabled the process is restarted on every file change.
// Waiting for graceful termination would slow down the turn around.
=> ProcessCleanupTimeout ?? (isHotReloadEnabled ? TimeSpan.FromSeconds(5) : TimeSpan.FromSeconds(0));
// Allow sufficient time for the process to exit gracefully and release resources (e.g., network ports).
=> ProcessCleanupTimeout ?? TimeSpan.FromSeconds(5);

private int _uniqueLogId;

Expand Down
34 changes: 34 additions & 0 deletions test/dotnet-watch.Tests/CommandLine/EnvironmentOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@

namespace Microsoft.DotNet.Watch.UnitTests;

public class EnvironmentOptionsTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetProcessCleanupTimeout_WithoutEnvironmentVariable_ReturnsDefaultTimeout(bool isHotReloadEnabled)
{
var envOptions = new EnvironmentOptions(
WorkingDirectory: "/test",
MuxerPath: "dotnet",
ProcessCleanupTimeout: null);

var timeout = envOptions.GetProcessCleanupTimeout(isHotReloadEnabled);

Assert.Equal(TimeSpan.FromSeconds(5), timeout);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetProcessCleanupTimeout_WithEnvironmentVariable_ReturnsSpecifiedTimeout(bool isHotReloadEnabled)
{
var customTimeout = TimeSpan.FromSeconds(10);
var envOptions = new EnvironmentOptions(
WorkingDirectory: "/test",
MuxerPath: "dotnet",
ProcessCleanupTimeout: customTimeout);

var timeout = envOptions.GetProcessCleanupTimeout(isHotReloadEnabled);

Assert.Equal(customTimeout, timeout);
}
}

public class BuildReporterTests
{
[Fact]
Expand Down
Loading