public void should_indicate_no_cpu_usage_when_process_does_nothing() { var pw = new ProcessWrapper("ruby", "-e 'sleep 30'"); pw.Execute(); pw.WaitForProcess(1000); var tpt = pw.ProcessTreeCPUUsageId; pw.WaitForProcess(2000); var tpt1 = pw.ProcessTreeCPUUsageId; pw.Dispose(); Assert.That(tpt, Is.EqualTo(tpt1)); }
public void should_indicate_cpu_usage_when_process_consumes_one() { var pw = new ProcessWrapper("ruby", "-e '100000000.times {|e| e}'"); pw.Execute(); pw.WaitForProcess(1); var tpt = pw.ProcessTreeCPUUsageId; pw.WaitForProcess(500); var tpt1 = pw.ProcessTreeCPUUsageId; pw.Dispose(); Assert.That(tpt, Is.Not.EqualTo(tpt1)); }
public void should_capture_std_error_output() { var err = new StringBuilder(); var pw = new ProcessWrapper("ruby", "-e '$stderr.puts(\"fle\")'"); pw.OnErrorOutput += output => err.Append(output); pw.Execute(); pw.WaitForProcess(5000); pw.Dispose(); Assert.That(err.ToString(), Is.Not.Empty); }
public static string UnixTotalProcessorTime(int processId) { var p = new ProcessWrapper("python",string.Format("{0} {1}", Path.Combine(Locations.SupportScriptsLocation, "cpu_times.py"), processId)); var processStrings = new List<String>(); var errorStrings = new List<String>(); p.OnStdOutput += s => { if (!s.IsNullOrEmpty()) processStrings.Add(s); }; p.OnErrorOutput += s => { if (!s.IsNullOrEmpty()) errorStrings.Add(s); }; p.Execute(); p.WaitForProcess(10000); p.Dispose(); return ParseCPUTreeUsageInfo(processStrings, errorStrings); }
public void should_capture_std_output() { var std = new StringBuilder(); var pw = new ProcessWrapper("ruby", "-e 'puts \"ff\"'"); pw.OnStdOutput += output => std.Append(output); pw.Execute(); pw.WaitForProcess(5000); pw.Dispose(); Assert.That(std.ToString(), Is.Not.Empty); }
public CheckoutInfo GetSourceRevision(string revision, string workingArea) { var scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_fetch.rb"); var process = new ProcessWrapper("ruby", scriptPath + " \"" + repoUrl + "\" " + revision + " " + " \"" + workingArea+"\""); var log = ""; process.OnStdOutput += s => { if (!s.IsNullOrEmpty()) log = s; }; string err_log = ""; process.OnErrorOutput += s => err_log += s; process.Execute(); process.WaitForProcess(GitTimeoutInMs); var exitcode = process.Dispose(); if (exitcode != 0) throw new InvalidProgramException("script failed: "+err_log); return new CheckoutInfo {Comment = log, Revision = revision}; }
public RevisionInfo GetLatestRevision() { string scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_remote_latest_rev.rb"); var process = new ProcessWrapper("ruby", scriptPath + " \"" + repoUrl+"\""); string result = ""; process.OnStdOutput += s => { if (result.Length == 0 && !s.IsNullOrEmpty()) { if (Regex.IsMatch(s, RevisionExtractingRegex)) result = Regex.Match(s, RevisionExtractingRegex).Groups[1].Value; } }; process.Execute(); process.WaitForProcess(GitTimeoutInMs); var exitcode = process.Dispose(); if (exitcode != 0) throw new InvalidProgramException(string.Format("script failed with exit code {1}: {0}", 1, exitcode)); if (result.IsNullOrEmpty()) throw new InvalidProgramException("Failed to retrieve repo revision"); return new RevisionInfo {Revision = result}; }
public void should_throw_an_exception_when_trying_to_get_process_snapshot_for_process_that_has_died() { var pw = new ProcessWrapper("ruby", @"-e exit 0"); pw.Execute(); pw.WaitForProcess(1000); var processId = pw.Id; // pw.Dispose(); Assert.That(ProcessHasExited(processId)); try { var tpt = pw.ProcessTreeCPUUsageId; Assert.Fail("the process should have been gone, operation should have failed"); } catch(InvalidOperationException) { // that's what we are aiming for ;) } pw.Dispose(); }
public void should_run_when_no_std_error_output_is_captured() { var pw = new ProcessWrapper("ruby", "-e '$stderr.puts(\"fle\")'"); pw.Execute(); pw.WaitForProcess(5000); }