From 88da31af7c6bafece196a6f94b33324ea538b276 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 25 Sep 2014 15:36:40 -0700 Subject: [PATCH] Cleanup. --- src/Microsoft.Net.Http.Server/WebListener.cs | 3 +- .../ServerTests.cs | 57 ++++++++----------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Microsoft.Net.Http.Server/WebListener.cs b/src/Microsoft.Net.Http.Server/WebListener.cs index e897f05e42..11288670c3 100644 --- a/src/Microsoft.Net.Http.Server/WebListener.cs +++ b/src/Microsoft.Net.Http.Server/WebListener.cs @@ -768,7 +768,8 @@ namespace Microsoft.Net.Http.Server uint statusCode; try { - statusCode = UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnectEx(_requestQueueHandle, connectionId, 0, nativeOverlapped); + statusCode = UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnectEx(requestQueueHandle: _requestQueueHandle, + connectionId: connectionId, reserved: 0, overlapped: nativeOverlapped); } catch (Win32Exception exception) { diff --git a/test/Microsoft.Net.Http.Server.FunctionalTests/ServerTests.cs b/test/Microsoft.Net.Http.Server.FunctionalTests/ServerTests.cs index f4abdb333d..e66e1f768e 100644 --- a/test/Microsoft.Net.Http.Server.FunctionalTests/ServerTests.cs +++ b/test/Microsoft.Net.Http.Server.FunctionalTests/ServerTests.cs @@ -17,15 +17,14 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_200OK_Success() { - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { - Task responseTask = SendRequestAsync(address); + var responseTask = SendRequestAsync(address); var context = await server.GetContextAsync(); context.Dispose(); - string response = await responseTask; + var response = await responseTask; Assert.Equal(string.Empty, response); } } @@ -33,8 +32,7 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_SendHelloWorld_Success() { - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { Task responseTask = SendRequestAsync(address); @@ -53,10 +51,9 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_EchoHelloWorld_Success() { - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { - Task responseTask = SendRequestAsync(address, "Hello World"); + var responseTask = SendRequestAsync(address, "Hello World"); var context = await server.GetContextAsync(); string input = new StreamReader(context.Request.Body).ReadToEnd(); @@ -67,7 +64,7 @@ namespace Microsoft.Net.Http.Server writer.Write("Hello World"); } - string response = await responseTask; + var response = await responseTask; Assert.Equal("Hello World", response); } } @@ -75,18 +72,17 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_ClientDisconnects_CallCanceled() { - TimeSpan interval = TimeSpan.FromSeconds(1); - ManualResetEvent canceled = new ManualResetEvent(false); + var interval = TimeSpan.FromSeconds(1); + var canceled = new ManualResetEvent(false); - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { using (var client = new HttpClient()) { - Task responseTask = client.GetAsync(address); + var responseTask = client.GetAsync(address); var context = await server.GetContextAsync(); - CancellationToken ct = context.DisconnectToken; + var ct = context.DisconnectToken; Assert.True(ct.CanBeCanceled, "CanBeCanceled"); Assert.False(ct.IsCancellationRequested, "IsCancellationRequested"); ct.Register(() => canceled.Set()); @@ -106,16 +102,15 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_Abort_CallCanceled() { - TimeSpan interval = TimeSpan.FromSeconds(1); - ManualResetEvent canceled = new ManualResetEvent(false); + var interval = TimeSpan.FromSeconds(1); + var canceled = new ManualResetEvent(false); - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { var responseTask = SendRequestAsync(address); var context = await server.GetContextAsync(); - CancellationToken ct = context.DisconnectToken; + var ct = context.DisconnectToken; Assert.True(ct.CanBeCanceled, "CanBeCanceled"); Assert.False(ct.IsCancellationRequested, "IsCancellationRequested"); ct.Register(() => canceled.Set()); @@ -134,16 +129,15 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_ConnectionCloseHeader_CancellationTokenFires() { - TimeSpan interval = TimeSpan.FromSeconds(1); - ManualResetEvent canceled = new ManualResetEvent(false); + var interval = TimeSpan.FromSeconds(1); + var canceled = new ManualResetEvent(false); - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { - Task responseTask = SendRequestAsync(address); + var responseTask = SendRequestAsync(address); var context = await server.GetContextAsync(); - CancellationToken ct = context.DisconnectToken; + var ct = context.DisconnectToken; Assert.True(ct.CanBeCanceled, "CanBeCanceled"); Assert.False(ct.IsCancellationRequested, "IsCancellationRequested"); ct.Register(() => canceled.Set()); @@ -159,7 +153,7 @@ namespace Microsoft.Net.Http.Server Assert.True(canceled.WaitOne(interval), "Disconnected"); Assert.True(ct.IsCancellationRequested, "IsCancellationRequested"); - string response = await responseTask; + var response = await responseTask; Assert.Equal("Hello World", response); } } @@ -167,16 +161,15 @@ namespace Microsoft.Net.Http.Server [Fact] public async Task Server_SetQueueLimit_Success() { - string address; - using (var server = Utilities.CreateHttpServer(out address)) + using (var server = Utilities.CreateHttpServer(out var address)) { server.SetRequestQueueLimit(1001); - Task responseTask = SendRequestAsync(address); + var responseTask = SendRequestAsync(address); var context = await server.GetContextAsync(); context.Dispose(); - string response = await responseTask; + var response = await responseTask; Assert.Equal(string.Empty, response); } }