Exemplo n.º 1
0
        Process StartNginx(string configFile)
        {
            var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Environment.CurrentDirectory = baseDir;

            Assert.IsTrue(File.Exists(configFile), "Config file should exist");

            Directory.CreateDirectory("logs");
            Directory.CreateDirectory("temp");

            var nginxProcess = Process.Start(new ProcessStartInfo
            {
                FileName  = "nginx",
                Arguments = "-c " + configFile + " -p ./ -g \"error_log logs/error.log;\"",
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false,
            });

            ChildProcessTracker.AddProcess(nginxProcess);

            Thread.Sleep(5000);

            if (nginxProcess.HasExited)
            {
                var nginxOutput = nginxProcess.StandardOutput.ReadToEnd() + "\n====STDERR===\n" + nginxProcess.StandardError.ReadToEnd();
                Console.WriteLine("Nginx exited with output:");
                Console.WriteLine(nginxOutput);
                File.WriteAllText("nginx_output.txt", nginxOutput);
            }

            Assert.IsFalse(nginxProcess.HasExited, "nginx process should be running");

            return(nginxProcess);
        }
Exemplo n.º 2
0
        void AssertNginxInPath()
        {
            Process nginxProcess = null;

            // Try to run nginx with version output parameter
            try
            {
                nginxProcess = Process.Start(new ProcessStartInfo {
                    FileName  = "nginx",
                    Arguments = "-v",
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    UseShellExecute        = false,
                });
                ChildProcessTracker.AddProcess(nginxProcess);
            }
            catch (Win32Exception exception)
            {
                if (nginxProcess != null && !nginxProcess.HasExited)
                {
                    nginxProcess.Kill();
                }
                // Throw an IgnoreException if nginx was not found
                Assert.Ignore("Unable to run Nginx server. Do you have nginx in your PATH? Skipping Nginx test.");
            }

            nginxProcess.WaitForExit(500);
            var nginxOutput = nginxProcess.StandardError.ReadToEnd();

            string versionPrefix = "nginx version: nginx/";

            if (!nginxOutput.StartsWith(versionPrefix))
            {
                Assert.Ignore("Nginx server was found, but did not respond as expected. Skipping Nginx tests.");
            }
        }