From 5f9f362ee7dbac9b127509ef4cab5087aefc2711 Mon Sep 17 00:00:00 2001 From: markekraus Date: Sat, 23 Sep 2017 07:40:53 -0500 Subject: [PATCH 1/6] Add Delay Test to WebListener --- .../Controllers/DelayController.cs | 32 +++++++++++++++++++ test/tools/WebListener/README.md | 24 ++++++++++++++ test/tools/WebListener/Startup.cs | 5 +++ .../tools/WebListener/Views/Home/Index.cshtml | 1 + 4 files changed, 62 insertions(+) create mode 100644 test/tools/WebListener/Controllers/DelayController.cs diff --git a/test/tools/WebListener/Controllers/DelayController.cs b/test/tools/WebListener/Controllers/DelayController.cs new file mode 100644 index 00000000000..310276bd15b --- /dev/null +++ b/test/tools/WebListener/Controllers/DelayController.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http.Extensions; +using mvc.Models; + +namespace mvc.Controllers +{ + public class DelayController : Controller + { + public JsonResult Index(int seconds) + { + if (seconds > 0){ + int milliseconds = seconds * 1000; + Thread.Sleep(milliseconds); + } + var getController = new GetController(); + getController.ControllerContext = this.ControllerContext; + return getController.Index(); + } + + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } +} diff --git a/test/tools/WebListener/README.md b/test/tools/WebListener/README.md index 8dc89520d86..802b4cc4fc9 100644 --- a/test/tools/WebListener/README.md +++ b/test/tools/WebListener/README.md @@ -59,6 +59,30 @@ Response when certificate is not provided in request: } ``` +## /Delay/ + +Returns the same results as the Get test. If a number is supplied, the server will wait that many seconds before returning a response. This can be used to test timeouts. + +```powershell +Invoke-WebRequest -Uri 'http://localhost:8083/Delay/5' +``` + +After 5 Seconds: + +```json +{ + "args": { + + }, + "origin": "127.0.0.1", + "headers": { + "User-Agent": "Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.15063.608", + "Host": "localhost:8083" + }, + "url": "http://localhost:8083/Delay/5" +} +``` + ## /Encoding/Utf8/ Returns page containing UTF-8 data. diff --git a/test/tools/WebListener/Startup.cs b/test/tools/WebListener/Startup.cs index 040721ee39e..00553c5e247 100644 --- a/test/tools/WebListener/Startup.cs +++ b/test/tools/WebListener/Startup.cs @@ -48,6 +48,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) template: "Redirect/{count?}", defaults: new {controller = "Redirect", action = "Index"} ); + routes.MapRoute( + name: "delay", + template: "Delay/{seconds?}", + defaults: new {controller = "Delay", action = "Index"} + ); }); } } diff --git a/test/tools/WebListener/Views/Home/Index.cshtml b/test/tools/WebListener/Views/Home/Index.cshtml index ffa4cc474ab..7b4669ce334 100644 --- a/test/tools/WebListener/Views/Home/Index.cshtml +++ b/test/tools/WebListener/Views/Home/Index.cshtml @@ -2,6 +2,7 @@