// Copyright 2012-2025 The NATS Authors // Licensed under the Apache License, Version 2.0 using System.Runtime.InteropServices; using Shouldly; using ZB.MOM.NatsNet.Server.Internal; namespace ZB.MOM.NatsNet.Server.Tests.Internal; /// /// Tests for SignalHandler — mirrors tests from server/signal_test.go. /// public class SignalHandlerTests { /// /// Mirrors CommandToSignal mapping tests. /// [Fact] // T:3158 public void CommandToUnixSignal_ShouldMapCorrectly() { SignalHandler.CommandToUnixSignal(ServerCommand.Stop).ShouldBe(UnixSignal.SigKill); SignalHandler.CommandToUnixSignal(ServerCommand.Quit).ShouldBe(UnixSignal.SigInt); SignalHandler.CommandToUnixSignal(ServerCommand.Reopen).ShouldBe(UnixSignal.SigUsr1); SignalHandler.CommandToUnixSignal(ServerCommand.Reload).ShouldBe(UnixSignal.SigHup); } /// /// Mirrors SetProcessName test. /// [Fact] // T:3155 public void SetProcessName_ShouldNotThrow() { Should.NotThrow(() => SignalHandler.SetProcessName("test-server")); } /// /// Verify IsWindowsService returns false on non-Windows. /// [Fact] // T:3149 public void IsWindowsService_ShouldReturnFalse() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; // Skip on Windows SignalHandler.IsWindowsService().ShouldBeFalse(); } /// /// Mirrors Run — service.go Run() simply invokes the start function. /// [Fact] // T:3148 public void Run_ShouldInvokeStartAction() { var called = false; SignalHandler.Run(() => called = true); called.ShouldBeTrue(); } /// /// ProcessSignal with invalid PID expression should return error. /// [Fact] // T:3157 public void ProcessSignal_InvalidPid_ShouldReturnError() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; // Skip on Windows var err = SignalHandler.ProcessSignal(ServerCommand.Stop, "not-a-pid"); err.ShouldNotBeNull(); } }