Skip to content

Commit

Permalink
#263 Add Caching_SetTtlAndStatusCode_Cached test diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Apr 18, 2017
1 parent 4e8872b commit 0ce85e2
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,28 @@ public async Task Caching_SetTtlAndStatusCode_Cached()
context.Response.CacheTtl = TimeSpan.FromSeconds(10);
context.Dispose();

var response = await responseTask;
HttpResponseMessage response;
try
{
response = await responseTask;
}
catch (Exception ex)
{
throw new Exception($"Failed to get first response for {status}", ex);
}
Assert.Equal(status, (int)response.StatusCode);
Assert.Equal(status.ToString(), response.Headers.GetValues("x-request-count").FirstOrDefault());
Assert.Equal(new byte[0], await response.Content.ReadAsByteArrayAsync());

// Send a second request and make sure we get the same response (without listening for one on the server).
response = await SendRequestAsync(address + status);
try
{
response = await SendRequestAsync(address + status);
}
catch (Exception ex)
{
throw new Exception($"Failed to get second response for {status}", ex);
}
Assert.Equal(status, (int)response.StatusCode);
Assert.Equal(status.ToString(), response.Headers.GetValues("x-request-count").FirstOrDefault());
Assert.Equal(new byte[0], await response.Content.ReadAsByteArrayAsync());
Expand Down Expand Up @@ -1137,7 +1152,7 @@ private async Task<HttpResponseMessage> SendRequestAsync(string uri, string meth
{
using (var handler = new HttpClientHandler() { AllowAutoRedirect = false })
{
using (var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5) })
using (var client = new HttpClient(handler) { Timeout = Utilities.DefaultTimeout })
{
var request = new HttpRequestMessage(new HttpMethod(method), uri);
if (!string.IsNullOrEmpty(extraHeader))
Expand Down

0 comments on commit 0ce85e2

Please sign in to comment.