Skip to content

Commit c126b90

Browse files
committed
Add test
1 parent fea681e commit c126b90

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/TestAssets/TestProjects/WatchHotReloadApp/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.Versioning;
99
using System.Threading;
1010
using System.Threading.Tasks;
11+
using System.Runtime.InteropServices;
1112

1213
// <metadata update handler placeholder>
1314

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ class AppUpdateHandler
721721
[PlatformSpecificFact(TestPlatforms.Windows)]
722722
public async Task GracefulTermination_Windows()
723723
{
724+
var tfm = ToolsetInfo.CurrentTargetFramework;
725+
724726
var testAsset = TestAssets.CopyTestAsset("WatchHotReloadApp")
725727
.WithSource();
726728

@@ -739,7 +741,7 @@ public async Task GracefulTermination_Windows()
739741

740742
await App.WaitForOutputLineContaining(MessageDescriptor.WaitingForChanges);
741743

742-
await App.WaitUntilOutputContains(new Regex(@"dotnet watch 🕵️ \[.*\] Windows Ctrl\+C handling enabled."));
744+
await App.WaitUntilOutputContains($"dotnet watch 🕵️ [WatchHotReloadApp ({tfm})] Windows Ctrl+C handling enabled.");
743745

744746
await App.WaitUntilOutputContains("Started");
745747

@@ -749,6 +751,37 @@ public async Task GracefulTermination_Windows()
749751
await App.WaitUntilOutputContains("exited with exit code 0.");
750752
}
751753

754+
[PlatformSpecificFact(TestPlatforms.AnyUnix)]
755+
public async Task GracefulTermination_Unix()
756+
{
757+
var tfm = ToolsetInfo.CurrentTargetFramework;
758+
759+
var testAsset = TestAssets.CopyTestAsset("WatchHotReloadApp")
760+
.WithSource();
761+
762+
var programPath = Path.Combine(testAsset.Path, "Program.cs");
763+
764+
UpdateSourceFile(programPath, src => src.Replace("// <metadata update handler placeholder>", """
765+
using var termSignalRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, _ =>
766+
{
767+
Console.WriteLine("SIGTERM detected! Performing cleanup...");
768+
});
769+
"""));
770+
771+
App.Start(testAsset, [], testFlags: TestFlags.ReadKeyFromStdin);
772+
773+
await App.WaitForOutputLineContaining(MessageDescriptor.WaitingForChanges);
774+
775+
await App.WaitUntilOutputContains($"dotnet watch 🕵️ [WatchHotReloadApp ({tfm})] Posix signal handlers registered.");
776+
777+
await App.WaitUntilOutputContains("Started");
778+
779+
App.SendControlC();
780+
781+
await App.WaitForOutputLineContaining("SIGTERM detected! Performing cleanup...");
782+
await App.WaitUntilOutputContains("exited with exit code 0.");
783+
}
784+
752785
[PlatformSpecificTheory(TestPlatforms.Windows, Skip = "https://github.com/dotnet/sdk/issues/49928")] // https://github.com/dotnet/sdk/issues/49307
753786
[CombinatorialData]
754787
public async Task BlazorWasm(bool projectSpecifiesCapabilities)

0 commit comments

Comments
 (0)