Do not block on async calls

This commit is contained in:
John Luo 2017-08-16 19:30:36 -07:00
parent 17852e5217
commit dc8d1d0788
5 changed files with 8 additions and 8 deletions

View File

@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener
Assert.True(response.Content.Headers.TryGetValues("content-length", out contentLength), "Content-Length"); Assert.True(response.Content.Headers.TryGetValues("content-length", out contentLength), "Content-Length");
Assert.Equal(FileLength.ToString(), contentLength.First()); Assert.Equal(FileLength.ToString(), contentLength.First());
Assert.Null(response.Headers.TransferEncodingChunked); Assert.Null(response.Headers.TransferEncodingChunked);
Assert.Equal(FileLength, response.Content.ReadAsByteArrayAsync().Result.Length); Assert.Equal(FileLength, (await response.Content.ReadAsByteArrayAsync()).Length);
} }
} }

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
Assert.Equal(200, (int)response.StatusCode); Assert.Equal(200, (int)response.StatusCode);
Assert.False(response.Headers.TransferEncodingChunked.HasValue, "Chunked"); Assert.False(response.Headers.TransferEncodingChunked.HasValue, "Chunked");
Assert.Equal(0, response.Content.Headers.ContentLength); Assert.Equal(0, response.Content.Headers.ContentLength);
Assert.Equal(string.Empty, response.Content.ReadAsStringAsync().Result); Assert.Equal(string.Empty, await response.Content.ReadAsStringAsync());
} }
} }

View File

@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
[ConditionalFact] [ConditionalFact]
public void ResponseBody_WriteContentLengthNotEnoughWritten_Throws() public async Task ResponseBody_WriteContentLengthNotEnoughWritten_Throws()
{ {
string address; string address;
using (Utilities.CreateHttpServer(out address, httpContext => using (Utilities.CreateHttpServer(out address, httpContext =>
@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
return httpContext.Response.Body.WriteAsync(new byte[5], 0, 5); return httpContext.Response.Body.WriteAsync(new byte[5], 0, 5);
})) }))
{ {
Assert.Throws<AggregateException>(() => SendRequestAsync(address).Result); await Assert.ThrowsAsync<HttpRequestException>(async () => await SendRequestAsync(address));
} }
} }

View File

@ -274,7 +274,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
Assert.True(response.Content.Headers.TryGetValues("content-length", out contentLength), "Content-Length"); Assert.True(response.Content.Headers.TryGetValues("content-length", out contentLength), "Content-Length");
Assert.Equal(FileLength.ToString(), contentLength.First()); Assert.Equal(FileLength.ToString(), contentLength.First());
Assert.Null(response.Headers.TransferEncodingChunked); Assert.Null(response.Headers.TransferEncodingChunked);
Assert.Equal(FileLength, response.Content.ReadAsByteArrayAsync().Result.Length); Assert.Equal(FileLength, (await response.Content.ReadAsByteArrayAsync()).Length);
} }
} }

View File

@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
} }
[ConditionalFact] [ConditionalFact]
public void Server_AppException_ClientReset() public async Task Server_AppException_ClientReset()
{ {
string address; string address;
using (Utilities.CreateHttpServer(out address, httpContext => using (Utilities.CreateHttpServer(out address, httpContext =>
@ -144,11 +144,11 @@ namespace Microsoft.AspNetCore.Server.HttpSys
})) }))
{ {
Task<string> requestTask = SendRequestAsync(address); Task<string> requestTask = SendRequestAsync(address);
Assert.Throws<AggregateException>(() => requestTask.Result); await Assert.ThrowsAsync<HttpRequestException>(async () => await requestTask);
// Do it again to make sure the server didn't crash // Do it again to make sure the server didn't crash
requestTask = SendRequestAsync(address); requestTask = SendRequestAsync(address);
Assert.Throws<AggregateException>(() => requestTask.Result); await Assert.ThrowsAsync<HttpRequestException>(async () => await requestTask);
} }
} }