public void StartStopExtension() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(); manager.FireOnWrapperStarted(); manager.FireBeforeWrapperStopped(); }
public void LoadExtensions() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(_logger); Assert.AreEqual(2, manager.Extensions.Count, "Two extensions should be loaded"); }
public void LoadExtensionsYaml() { var manager = new WinSWExtensionManager(this._testServiceDescriptorYaml); manager.LoadExtensions(); Assert.AreEqual(2, manager.Extensions.Count, "Two extensions should be loaded"); }
public void ShouldKillTheSpawnedProcess() { var winswId = "myAppWithRunaway"; var extensionId = "runawayProcessKiller"; var tmpDir = FilesystemTestHelper.CreateTmpDirectory(); // Prepare the env var String varName = WinSWSystem.ENVVAR_NAME_SERVICE_ID; var env = new Dictionary <string, string>(); env.Add("varName", winswId); // Spawn the test process var scriptFile = Path.Combine(tmpDir, "dosleep.bat"); var envFile = Path.Combine(tmpDir, "env.txt"); File.WriteAllText(scriptFile, "set > " + envFile + "\nsleep 100500"); Process proc = new Process(); var ps = proc.StartInfo; ps.FileName = scriptFile; ProcessHelper.StartProcessAndCallbackForExit(proc, envVars: env); try { // Generate extension and ensure that the roundtrip is correct //TODO: checkWinSWEnvironmentVariable should be true, but it does not work due to proc.StartInfo.EnvironmentVariables var pidfile = Path.Combine(tmpDir, "process.pid"); var sd = ConfigXmlBuilder.create(id: winswId) .WithRunawayProcessKiller(new RunawayProcessKillerExtension(pidfile, checkWinSWEnvironmentVariable: false), extensionId) .ToServiceDescriptor(); WinSWExtensionManager manager = new WinSWExtensionManager(sd); manager.LoadExtensions(); var extension = manager.Extensions[extensionId] as RunawayProcessKillerExtension; Assert.IsNotNull(extension, "RunawayProcessKillerExtension should be loaded"); Assert.AreEqual(pidfile, extension.Pidfile, "PidFile should have been retained during the config roundtrip"); // Inject PID File.WriteAllText(pidfile, proc.Id.ToString()); // Try to terminate Assert.That(!proc.HasExited, "Process " + proc + " has exited before the RunawayProcessKiller extension invocation"); extension.OnWrapperStarted(); Assert.That(proc.HasExited, "Process " + proc + " should have been terminated by RunawayProcessKiller"); } finally { if (!proc.HasExited) { Console.Error.WriteLine("Test: Killing runaway process with ID=" + proc.Id); ProcessHelper.StopProcessAndChildren(proc.Id, TimeSpan.FromMilliseconds(100), false); if (!proc.HasExited) { // The test is failed here anyway, but we add additional diagnostics info Console.Error.WriteLine("Test: ProcessHelper failed to properly terminate process with ID=" + proc.Id); } } } }
public void StartStopExtension() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(); manager.FireOnWrapperStarted(); manager.FireBeforeWrapperStopped(); }
public void StartStopExtension() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(_logger); manager.OnStart(_logger); manager.OnStop(_logger); }
public void ShouldKillTheSpawnedProcess() { Assert.Ignore(); var winswId = "myAppWithRunaway"; var extensionId = "runawayProcessKiller"; var tmpDir = FilesystemTestHelper.CreateTmpDirectory(); // Spawn the test process Process proc = new Process(); var ps = proc.StartInfo; ps.FileName = "cmd.exe"; ps.Arguments = "/c pause"; ps.UseShellExecute = false; ps.RedirectStandardOutput = true; ps.EnvironmentVariables[WinSWSystem.ENVVAR_NAME_SERVICE_ID] = winswId; proc.Start(); try { // Generate extension and ensure that the roundtrip is correct var pidfile = Path.Combine(tmpDir, "process.pid"); var sd = ConfigXmlBuilder.create(id: winswId) .WithRunawayProcessKiller(new RunawayProcessKillerExtension(pidfile), extensionId) .ToServiceDescriptor(); WinSWExtensionManager manager = new WinSWExtensionManager(sd); manager.LoadExtensions(); var extension = manager.Extensions[extensionId] as RunawayProcessKillerExtension; Assert.IsNotNull(extension, "RunawayProcessKillerExtension should be loaded"); Assert.AreEqual(pidfile, extension.Pidfile, "PidFile should have been retained during the config roundtrip"); // Inject PID File.WriteAllText(pidfile, proc.Id.ToString()); // Try to terminate Assert.That(!proc.HasExited, "Process " + proc + " has exited before the RunawayProcessKiller extension invocation"); _ = proc.StandardOutput.Read(); extension.OnWrapperStarted(); Assert.That(proc.HasExited, "Process " + proc + " should have been terminated by RunawayProcessKiller"); } finally { if (!proc.HasExited) { Console.Error.WriteLine("Test: Killing runaway process with ID=" + proc.Id); ProcessHelper.StopProcessAndChildren(proc.Id, TimeSpan.FromMilliseconds(100), false); if (!proc.HasExited) { // The test is failed here anyway, but we add additional diagnostics info Console.Error.WriteLine("Test: ProcessHelper failed to properly terminate process with ID=" + proc.Id); } } } }
public WrapperService(ServiceDescriptor descriptor) { _descriptor = descriptor; ServiceName = _descriptor.Id; ExtensionManager = new WinSWExtensionManager(_descriptor); CanShutdown = true; CanStop = true; CanPauseAndContinue = false; AutoLog = true; _systemShuttingdown = false; }
public void LoadExtensions() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(); Assert.AreEqual(1, manager.Extensions.Count, "One extension should be loaded"); // Check the file is correct var extension = manager.Extensions["killRunawayProcess"] as RunawayProcessKillerExtension; Assert.IsNotNull(extension, "RunawayProcessKillerExtension should be loaded"); Assert.AreEqual("foo/bar/pid.txt", extension.Pidfile, "Loaded PID file path is not equal to the expected one"); Assert.AreEqual(5000, extension.StopTimeout.TotalMilliseconds, "Loaded Stop Timeout is not equal to the expected one"); Assert.AreEqual(true, extension.StopParentProcessFirst, "Loaded StopParentFirst is not equal to the expected one"); }
public WrapperService(IWinSWConfiguration descriptor) { this.descriptor = descriptor; this.ServiceName = this.descriptor.Id; this.ExtensionManager = new WinSWExtensionManager(this.descriptor); this.CanShutdown = true; this.CanStop = true; this.CanPauseAndContinue = false; this.AutoLog = true; this.systemShuttingdown = false; // Register the event log provider eventLogProvider.Service = this; }
public WrapperService(ServiceDescriptor descriptor) { _descriptor = descriptor; ServiceName = _descriptor.Id; ExtensionManager = new WinSWExtensionManager(_descriptor); CanShutdown = true; CanStop = true; CanPauseAndContinue = false; AutoLog = true; _systemShuttingdown = false; // Register the event log provider eventLogProvider.service = this; }
public WrapperService(ServiceDescriptor descriptor) { _descriptor = descriptor; ServiceName = _descriptor.Id; ExtensionManager = new WinSWExtensionManager(_descriptor); CanShutdown = true; CanStop = true; CanPauseAndContinue = false; AutoLog = true; _systemShuttingdown = false; // Register the event log provider eventLogProvider.service = this; }
public void LoadExtensions() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(); Assert.AreEqual(1, manager.Extensions.Count, "One extension should be loaded"); // Check the file is correct var extension = manager.Extensions["killRunawayProcess"] as RunawayProcessKillerExtension; Assert.IsNotNull(extension, "RunawayProcessKillerExtension should be loaded"); Assert.AreEqual("foo/bar/pid.txt", extension.Pidfile, "Loaded PID file path is not equal to the expected one"); Assert.AreEqual(5000, extension.StopTimeout.TotalMilliseconds, "Loaded Stop Timeout is not equal to the expected one"); Assert.AreEqual(true, extension.StopParentProcessFirst, "Loaded StopParentFirst is not equal to the expected one"); }
public void LoadExtensions() { WinSWExtensionManager manager = new WinSWExtensionManager(_testServiceDescriptor); manager.LoadExtensions(); Assert.AreEqual(2, manager.Extensions.Count, "Two extensions should be loaded"); }