From f09fd4e49fd5fb9d500733efe45cf7e21999cbc4 Mon Sep 17 00:00:00 2001 From: Philippe Miossec Date: Tue, 17 Oct 2017 23:09:19 +0200 Subject: [PATCH 1/2] Add possibility to configure GitHubClient timeout (#963) A first attempt to fix the problem describe in #963 by adding a possibility to extend the default timeout value (100s) that is too short to be able to post assets in github release. --- Octokit.Reactive/IObservableGitHubClient.cs | 10 ++++++++++ Octokit.Reactive/ObservableGitHubClient.cs | 6 ++++++ Octokit.Tests/GitHubClientTests.cs | 15 +++++++++++++++ Octokit/GitHubClient.cs | 13 +++++++++++++ Octokit/Http/Connection.cs | 9 +++++++++ Octokit/Http/HttpClientAdapter.cs | 5 +++++ Octokit/Http/IConnection.cs | 6 ++++++ Octokit/Http/IHttpClient.cs | 7 +++++++ Octokit/IGitHubClient.cs | 10 ++++++++++ 9 files changed, 81 insertions(+) diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index e971972efb..234b8abaee 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -6,6 +6,16 @@ public interface IObservableGitHubClient : IApiInfoProvider { IConnection Connection { get; } + /// + /// Set the GitHub Api request timeout. + /// Useful to set a specific timeout for lengthy operations, such as uploading release assets + /// + /// + /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx + /// + /// The Timeout value + void SetRequestsTimeout(TimeSpan timeout); + IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } IObservableIssuesClient Issue { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 3745687f44..7dd3a2febd 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -54,6 +54,12 @@ public IConnection Connection get { return _gitHubClient.Connection; } } + public void SetRequestsTimeout(TimeSpan timeout) + { + + _gitHubClient.SetRequestsTimeout(timeout); + } + public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } public IObservableIssuesClient Issue { get; private set; } diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 9f466e7dfa..b258c7d4fb 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -132,6 +132,21 @@ public void IsRetrievedFromCredentialStore() } } + public class SettingRequestsTimeout + { + [Fact] + public void WhenSettingTimeoutThatSetTheRequestsTimeoutOnTheUnderlyingHttpClient() + { + var httpClient = Substitute.For(); + var client = new GitHubClient(new Connection(new ProductHeaderValue("OctokitTests"), httpClient)); + + client.SetRequestsTimeout(TimeSpan.FromSeconds(15)); + + + httpClient.Received(1).SetRequestsTimeout(TimeSpan.FromSeconds(15)); + } + } + public class TheLastApiInfoProperty { [Fact] diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index a00614c4f5..9df01688cb 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -99,6 +99,19 @@ public GitHubClient(IConnection connection) Reaction = new ReactionsClient(apiConnection); } + /// + /// Set the GitHub Api request timeout. + /// Useful to set a specific timeout for lengthy operations, such as uploading release assets + /// + /// + /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx + /// + /// The Timeout value + public void SetRequestsTimeout(TimeSpan timeout) + { + Connection.SetRequestsTimeout(timeout); + } + /// /// Gets the latest API Info - this will be null if no API calls have been made /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 7ca86ff77a..abe23c7e18 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -752,5 +752,14 @@ static string GetVersionInformation() return _versionInformation; } + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + public void SetRequestsTimeout(TimeSpan timeout) + { + _httpClient.SetRequestsTimeout(timeout); + } } } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 24c56cca34..764693242f 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -264,6 +264,11 @@ public static async Task CloneHttpRequestMessageAsync(HttpRe return newRequest; } + + public void SetRequestsTimeout(TimeSpan timeout) + { + _http.Timeout = timeout; + } } internal class RedirectHandler : DelegatingHandler diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index ad649d7572..ab16e8d7e1 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -292,5 +292,11 @@ public interface IConnection : IApiInfoProvider /// the default with just these credentials. /// Credentials Credentials { get; set; } + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + void SetRequestsTimeout(TimeSpan timeout); } } diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index f554d750dc..a4535ce4c2 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -19,5 +19,12 @@ public interface IHttpClient : IDisposable /// Used to cancel the request /// A of Task Send(IRequest request, CancellationToken cancellationToken); + + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + void SetRequestsTimeout(TimeSpan timeout); } } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 0fd4b914e1..ae51df3984 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -7,6 +7,16 @@ namespace Octokit /// public interface IGitHubClient : IApiInfoProvider { + /// + /// Set the GitHub Api request timeout. + /// Useful to set a specific timeout for lengthy operations, such as uploading release assets + /// + /// + /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx + /// + /// The Timeout value + void SetRequestsTimeout(TimeSpan timeout); + /// /// Provides a client connection to make rest requests to HTTP endpoints. /// From ba6af91dbf02365166c66e656de216a780715a33 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 26 Oct 2017 22:16:43 +1000 Subject: [PATCH 2/2] Rename to SetRequestTimeout Make comments consistent --- Octokit.Reactive/IObservableGitHubClient.cs | 2 +- Octokit.Reactive/ObservableGitHubClient.cs | 12 +++++++-- Octokit.Tests/GitHubClientTests.cs | 30 ++++++++++----------- Octokit/GitHubClient.cs | 4 +-- Octokit/Http/Connection.cs | 8 +++--- Octokit/Http/HttpClientAdapter.cs | 6 ++++- Octokit/Http/IConnection.cs | 6 ++--- Octokit/Http/IHttpClient.cs | 6 ++--- Octokit/IGitHubClient.cs | 2 +- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 234b8abaee..2b2cb50b3e 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -14,7 +14,7 @@ public interface IObservableGitHubClient : IApiInfoProvider /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx /// /// The Timeout value - void SetRequestsTimeout(TimeSpan timeout); + void SetRequestTimeout(TimeSpan timeout); IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 7dd3a2febd..87dc1705f2 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -54,10 +54,18 @@ public IConnection Connection get { return _gitHubClient.Connection; } } - public void SetRequestsTimeout(TimeSpan timeout) + /// + /// Set the GitHub Api request timeout. + /// Useful to set a specific timeout for lengthy operations, such as uploading release assets + /// + /// + /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx + /// + /// The Timeout value + public void SetRequestTimeout(TimeSpan timeout) { - _gitHubClient.SetRequestsTimeout(timeout); + _gitHubClient.SetRequestTimeout(timeout); } public IObservableAuthorizationsClient Authorization { get; private set; } diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index b258c7d4fb..2a02aaa855 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -132,21 +132,6 @@ public void IsRetrievedFromCredentialStore() } } - public class SettingRequestsTimeout - { - [Fact] - public void WhenSettingTimeoutThatSetTheRequestsTimeoutOnTheUnderlyingHttpClient() - { - var httpClient = Substitute.For(); - var client = new GitHubClient(new Connection(new ProductHeaderValue("OctokitTests"), httpClient)); - - client.SetRequestsTimeout(TimeSpan.FromSeconds(15)); - - - httpClient.Received(1).SetRequestsTimeout(TimeSpan.FromSeconds(15)); - } - } - public class TheLastApiInfoProperty { [Fact] @@ -211,5 +196,20 @@ public async Task ReturnsObjectIfNotNew() var temp = connection.Received(1).GetLastApiInfo(); } } + + public class TheSetRequestTimeoutMethod + { + [Fact] + public void SetsTheTimeoutOnTheUnderlyingHttpClient() + { + var httpClient = Substitute.For(); + var client = new GitHubClient(new Connection(new ProductHeaderValue("OctokitTests"), httpClient)); + + client.SetRequestTimeout(TimeSpan.FromSeconds(15)); + + + httpClient.Received(1).SetRequestTimeout(TimeSpan.FromSeconds(15)); + } + } } } diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 9df01688cb..a630e91254 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -107,9 +107,9 @@ public GitHubClient(IConnection connection) /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx /// /// The Timeout value - public void SetRequestsTimeout(TimeSpan timeout) + public void SetRequestTimeout(TimeSpan timeout) { - Connection.SetRequestsTimeout(timeout); + Connection.SetRequestTimeout(timeout); } /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index abe23c7e18..021d5be8f0 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -754,12 +754,12 @@ static string GetVersionInformation() } /// - /// Set the timespan to wait before the requests to GitHub api times out. + /// Set the GitHub Api request timeout. /// - /// the timespan to wait before a request to GitHub api times out - public void SetRequestsTimeout(TimeSpan timeout) + /// The Timeout value + public void SetRequestTimeout(TimeSpan timeout) { - _httpClient.SetRequestsTimeout(timeout); + _httpClient.SetRequestTimeout(timeout); } } } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 764693242f..ca14a34821 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -265,7 +265,11 @@ public static async Task CloneHttpRequestMessageAsync(HttpRe return newRequest; } - public void SetRequestsTimeout(TimeSpan timeout) + /// + /// Set the GitHub Api request timeout. + /// + /// The Timeout value + public void SetRequestTimeout(TimeSpan timeout) { _http.Timeout = timeout; } diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index ab16e8d7e1..98c0380c0f 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -294,9 +294,9 @@ public interface IConnection : IApiInfoProvider Credentials Credentials { get; set; } /// - /// Set the timespan to wait before the requests to GitHub api times out. + /// Set the GitHub Api request timeout. /// - /// the timespan to wait before a request to GitHub api times out - void SetRequestsTimeout(TimeSpan timeout); + /// The Timeout value + void SetRequestTimeout(TimeSpan timeout); } } diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index a4535ce4c2..584bef9f79 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -22,9 +22,9 @@ public interface IHttpClient : IDisposable /// - /// Set the timespan to wait before the requests to GitHub api times out. + /// Set the GitHub Api request timeout. /// - /// the timespan to wait before a request to GitHub api times out - void SetRequestsTimeout(TimeSpan timeout); + /// The Timeout value + void SetRequestTimeout(TimeSpan timeout); } } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index ae51df3984..e411dc0cdc 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -15,7 +15,7 @@ public interface IGitHubClient : IApiInfoProvider /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx /// /// The Timeout value - void SetRequestsTimeout(TimeSpan timeout); + void SetRequestTimeout(TimeSpan timeout); /// /// Provides a client connection to make rest requests to HTTP endpoints.