Potentially fix RunawayProcessKillerTest

pull/393/head
NextTurn 2019-10-21 00:00:00 +08:00
parent e06ae851f4
commit 5a42863fdc
No known key found for this signature in database
GPG Key ID: 17A0D50ADDE1A0C4
1 changed files with 7 additions and 10 deletions

View File

@ -71,19 +71,15 @@ $@"<service>
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 + "\npause");
Process proc = new Process();
var ps = proc.StartInfo;
ps.FileName = scriptFile;
ProcessHelper.StartProcessAndCallbackForExit(proc, envVars: env);
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
{
@ -103,6 +99,7 @@ $@"<service>
// 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");
}