Exemple #1
0
        public void Nginx_SingleRequest()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxBasicConfig.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            var result = GetHttp("http://localhost:8182");

            app.Stop();
            StopNginx(nginx);

            Assert.AreEqual(expectedResult, result);
        }
Exemple #2
0
        public void Nginx_ManyRequests_Keepalive()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxKeepalive.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            Task <string>[] results = new Task <string> [500];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = GetHttpAsync("http://localhost:8182");
                Thread.Sleep(20);
            }

            // Count the number of correct results
            int successCount = 0;
            // We will allow 2% of errors
            int minimumSuccessCount = (int)(results.Length * 0.95);

            for (int i = 0; i < results.Length; i++)
            {
                results[i].Wait(20000);

                var result = results[i].Result;
                if (result == expectedResult)
                {
                    successCount++;
                }
            }

            Assert.GreaterOrEqual(successCount, minimumSuccessCount, "At least 95% of requests should be successful");

            StopNginx(nginx);
            app.Stop();
            appThread.Join(500);
        }
Exemple #3
0
        public void Nginx_ManyRequests_Keepalive()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxKeepalive.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            Task <string>[] results = new Task <string> [1000];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = GetHttpAsync("http://localhost:8182");
                Thread.Sleep(1);
            }

            for (int i = 0; i < results.Length; i++)
            {
                results[i].Wait(20000);
                var result = results[i].Result;
                Assert.AreEqual(expectedResult, result);
            }

            StopNginx(nginx);
            app.Stop();
            appThread.Join(500);
        }