コード例 #1
0
        public void ShouldPropagateVariablesInUppercase()
        {
            Environment.SetEnvironmentVariable("TEST_KEY", "TEST_VALUE");

            var    tmpDir     = FilesystemTestHelper.CreateTmpDirectory();
            string envFile    = Path.Combine(tmpDir, "env.properties");
            string scriptFile = Path.Combine(tmpDir, "printenv.bat");

            File.WriteAllText(scriptFile, "set > " + envFile);

            Process proc = new Process();
            var     ps   = proc.StartInfo;

            ps.FileName = scriptFile;

            ProcessHelper.StartProcessAndCallbackForExit(proc);
            var exited = proc.WaitForExit(5000);

            if (!exited)
            {
                Assert.Fail("Process " + proc + " didn't exit after 5 seconds");
            }

            // Check several veriables, which are expected to be in Uppercase
            var envVars = FilesystemTestHelper.parseSetOutput(envFile);

            string[] keys = new string[envVars.Count];
            envVars.Keys.CopyTo(keys, 0);
            string availableVars = "[" + string.Join(",", keys) + "]";

            Assert.That(envVars.ContainsKey("TEST_KEY"), "No TEST_KEY in the injected vars: " + availableVars);

            // And just ensure that the parsing logic is case-sensitive
            Assert.That(!envVars.ContainsKey("test_key"), "Test error: the environment parsing logic is case-insensitive");
        }
コード例 #2
0
        public void ShouldNotHangWhenWritingLargeStringToStdOut()
        {
            var    tmpDir       = FilesystemTestHelper.CreateTmpDirectory();
            String scriptFile   = Path.Combine(tmpDir, "print_lots_to_stdout.bat");
            var    lotsOfStdOut = string.Join("", _Range(1, 1000));

            File.WriteAllText(scriptFile, string.Format("echo \"{0}\"", lotsOfStdOut));

            Process proc = new Process();
            var     ps   = proc.StartInfo;

            ps.FileName = scriptFile;

            ProcessHelper.StartProcessAndCallbackForExit(proc);
            var exited = proc.WaitForExit(5000);

            if (!exited)
            {
                Assert.Fail("Process " + proc + " didn't exit after 5 seconds");
            }
        }
コード例 #3
0
        public void ShouldKillChild()
        {
            const int childCount       = 4;
            string    sleep20sec       = "timeout 20";
            var       tmpDir           = FilesystemTestHelper.CreateTmpDirectory();
            string    childScriptFile  = Path.Combine(tmpDir, "child.bat");
            string    parentScriptFile = Path.Combine(tmpDir, "parent.bat");

            File.WriteAllText(childScriptFile, sleep20sec);
            File.WriteAllLines(parentScriptFile, Repeat("start child.bat", childCount));
            File.AppendAllText(parentScriptFile, "pause");

            Process proc = new Process();
            var     ps   = proc.StartInfo;

            ps.FileName         = parentScriptFile;
            ps.WorkingDirectory = tmpDir;
            proc.Start();
            proc.WaitForExit(1000);

            ProcessHelper.StopProcessAndChildren(proc.Id, TimeSpan.FromSeconds(1), false);

            Assert.AreEqual(0, ProcessHelper.GetChildPids(proc.Id).Count);
        }