public void WhenManagingManyProcesses_ReturnsAllProcessIds() { processes = new[] { IFTestHelper.ExecuteWithWait("nop"), IFTestHelper.ExecuteWithWait("nop"), IFTestHelper.ExecuteWithWait("nop"), IFTestHelper.ExecuteWithWait("nop"), IFTestHelper.ExecuteWithWait("nop"), IFTestHelper.ExecuteWithWait("nop"), }; foreach (var process in processes) { jobObject.AssignProcessToJob(process); } var processIds = jobObject.GetProcessIds(); Assert.Collection(processIds, x => Assert.Equal(processes[0].Id, x), x => Assert.Equal(processes[1].Id, x), x => Assert.Equal(processes[2].Id, x), x => Assert.Equal(processes[3].Id, x), x => Assert.Equal(processes[4].Id, x), x => Assert.Equal(processes[5].Id, x) ); }
public void WhenManagingOneProcess_ReturnsSingleProcessId() { processes = new[] { IFTestHelper.ExecuteWithWait("nop"), }; jobObject.AssignProcessToJob(processes[0]); var processIds = jobObject.GetProcessIds(); Assert.Collection(processIds, x => Assert.Equal(processes[0].Id, x) ); }
public void GetQueuedCompletionStatus_ForkBomb_DoesHaveLimitViolation() { using (var jobObject = new JobObject()) { jobObject.SetActiveProcessLimit(2); var process = IFTestHelper.ExecuteWithWait("fork-bomb"); jobObject.AssignProcessToJob(process); IFTestHelper.Continue(process); process.WaitForExit(1000); var msgs = jobObject.GetQueuedCompletionStatus(); Assert.Contains(msgs, x => x == JobObject.CompletionMsg.ActiveProcessLimit); } }
public void WhenManagedProcessCreatesChildProcess_ReturnsAllProcessIds() { // Arrange: var process = IFTestHelper.ExecuteWithWait("create-child"); jobObject.AssignProcessToJob(process); process.StandardInput.WriteLine(); var pidLine = process.StandardOutput.ReadLine(); int pid = Int32.Parse(pidLine); // Act: var managedProcesses = jobObject.GetProcessIds(); // Assert: Assert.Contains(process.Id, managedProcesses); Assert.Contains(pid, managedProcesses); process.StandardInput.WriteLine(); process.WaitForExit(); Assert.True(IFTestHelper.Succeeded(process)); }
public void SetActiveProcessLimit_StopsForkBomb() { using (var jobObject = new JobObject()) { jobObject.SetActiveProcessLimit(2); var process = IFTestHelper.ExecuteWithWait("fork-bomb"); jobObject.AssignProcessToJob(process); IFTestHelper.Continue(process); process.WaitForExit(1000); var hasExited = process.HasExited; if (!hasExited) { process.Kill(); } if (!hasExited) { Console.WriteLine(process.StandardOutput.ReadToEnd()); Console.Error.WriteLine(process.StandardError.ReadToEnd()); } Assert.True(hasExited, "Active process limit was not enforced"); } }
public void CanTerminateAndWaitForObjectsUnderJobObject() { JobObject jobObject = new JobObject(); Process p = null; try { p = IFTestHelper.ExecuteWithWait("nop"); jobObject.AssignProcessToJob(p); jobObject.TerminateProcessesAndWait(1000); IFTestHelper.ContinueAndWait(p, timeout: 1000); Assert.True(p.HasExited); } finally { if (!p.HasExited) { p.Kill(); } } }