mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 21:09:51 +00:00
Fix timeout getting multiple repositories (#1411)
* add test * [WIP] * put logic for redirects outside of delegating handler * change send method * format code * reorganized http client adapter * change HttpClientAdapter * rework http redirect tests - still an issue with accessing the response.RequestMessage.Content property as it is disposed * remove some unused lines in httpclientadapter * Reworked redirect implementation to fully clone http request and re-use it later Now the skipped test from #874 works! Also had to fix the new ReturnsRenamedRepository test as the ionide repo was renamed again
This commit is contained in:
committed by
Ryan Gribble
parent
ef0da2f84d
commit
5b9e23c2fb
@@ -14,10 +14,12 @@ namespace Octokit.Tests.Http
|
||||
[Fact]
|
||||
public async Task OkStatusShouldPassThrough()
|
||||
{
|
||||
var invoker = CreateInvoker(new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Get);
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.Equal(response.StatusCode, HttpStatusCode.OK);
|
||||
Assert.Same(response.RequestMessage, httpRequestMessage);
|
||||
@@ -32,11 +34,12 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(statusCode);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.org/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Post);
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.Equal(response.RequestMessage.Method, httpRequestMessage.Method);
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
@@ -48,11 +51,12 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(HttpStatusCode.SeeOther);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.org/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Post);
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.Equal(HttpMethod.Get, response.RequestMessage.Method);
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
@@ -64,12 +68,13 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(HttpStatusCode.Redirect);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.org/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Get);
|
||||
httpRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("fooAuth", "aparam");
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
Assert.Equal("fooAuth", response.RequestMessage.Headers.Authorization.Scheme);
|
||||
@@ -86,12 +91,13 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(statusCode);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.net/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Get);
|
||||
httpRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("fooAuth", "aparam");
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
Assert.Null(response.RequestMessage.Headers.Authorization);
|
||||
@@ -106,16 +112,16 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(statusCode);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.org/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Post);
|
||||
httpRequestMessage.Content = new StringContent("Hello World");
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.Equal(response.RequestMessage.Method, httpRequestMessage.Method);
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
Assert.Equal("Hello World", await response.RequestMessage.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
// POST see other with content
|
||||
@@ -125,12 +131,13 @@ namespace Octokit.Tests.Http
|
||||
var redirectResponse = new HttpResponseMessage(HttpStatusCode.SeeOther);
|
||||
redirectResponse.Headers.Location = new Uri("http://example.org/bar");
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse,
|
||||
new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var handler = CreateMockHttpHandler(redirectResponse, new HttpResponseMessage(HttpStatusCode.OK));
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Post);
|
||||
httpRequestMessage.Content = new StringContent("Hello World");
|
||||
|
||||
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
var response = await adapter.SendAsync(httpRequestMessage, new CancellationToken());
|
||||
|
||||
Assert.Equal(HttpMethod.Get, response.RequestMessage.Method);
|
||||
Assert.NotSame(response.RequestMessage, httpRequestMessage);
|
||||
@@ -145,14 +152,14 @@ namespace Octokit.Tests.Http
|
||||
|
||||
var redirectResponse2 = new HttpResponseMessage(HttpStatusCode.Found);
|
||||
redirectResponse2.Headers.Location = new Uri("http://example.org/foo");
|
||||
|
||||
|
||||
var invoker = CreateInvoker(redirectResponse, redirectResponse2);
|
||||
|
||||
var handler = CreateMockHttpHandler(redirectResponse, redirectResponse2);
|
||||
var adapter = new HttpClientAdapter(handler);
|
||||
|
||||
var httpRequestMessage = CreateRequest(HttpMethod.Get);
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => invoker.SendAsync(httpRequestMessage, new CancellationToken()));
|
||||
() => adapter.SendAsync(httpRequestMessage, new CancellationToken()));
|
||||
}
|
||||
|
||||
static HttpRequestMessage CreateRequest(HttpMethod method)
|
||||
@@ -163,14 +170,9 @@ namespace Octokit.Tests.Http
|
||||
return httpRequestMessage;
|
||||
}
|
||||
|
||||
static HttpMessageInvoker CreateInvoker(HttpResponseMessage httpResponseMessage1, HttpResponseMessage httpResponseMessage2 = null)
|
||||
static Func<HttpMessageHandler> CreateMockHttpHandler(HttpResponseMessage httpResponseMessage1, HttpResponseMessage httpResponseMessage2 = null)
|
||||
{
|
||||
var redirectHandler = new RedirectHandler
|
||||
{
|
||||
InnerHandler = new MockRedirectHandler(httpResponseMessage1, httpResponseMessage2)
|
||||
};
|
||||
var invoker = new HttpMessageInvoker(redirectHandler);
|
||||
return invoker;
|
||||
return () => new MockRedirectHandler(httpResponseMessage1, httpResponseMessage2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user