From fe25166478cfa03873d02aad5262b8b107abad66 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 17 Jul 2023 15:21:10 +0200 Subject: [PATCH] Better http timeout and retrying values --- DistTestCore/Codex/CodexAccess.cs | 13 ++++--------- .../Helpers/PeerConnectionTestHelpers.cs | 3 +-- DistTestCore/Http.cs | 19 +++---------------- DistTestCore/OnlineCodexNode.cs | 6 ------ DistTestCore/Timing.cs | 6 +++--- 5 files changed, 11 insertions(+), 36 deletions(-) diff --git a/DistTestCore/Codex/CodexAccess.cs b/DistTestCore/Codex/CodexAccess.cs index b6ae9fe..a38aa5d 100644 --- a/DistTestCore/Codex/CodexAccess.cs +++ b/DistTestCore/Codex/CodexAccess.cs @@ -22,17 +22,12 @@ namespace DistTestCore.Codex public CodexDebugResponse GetDebugInfo() { - return Http(TimeSpan.FromSeconds(60)).HttpGetJson("debug/info"); + return Http().HttpGetJson("debug/info"); } public CodexDebugPeerResponse GetDebugPeer(string peerId) { - return GetDebugPeer(peerId, TimeSpan.FromSeconds(10)); - } - - public CodexDebugPeerResponse GetDebugPeer(string peerId, TimeSpan timeout) - { - var http = Http(timeout); + var http = Http(); var str = http.HttpGetString($"debug/peer/{peerId}"); if (str.ToLowerInvariant() == "unable to find peer!") @@ -88,9 +83,9 @@ namespace DistTestCore.Codex return Http().HttpGetString($"connect/{peerId}?addrs={peerMultiAddress}"); } - private Http Http(TimeSpan? timeoutOverride = null) + private Http Http() { - return new Http(log, timeSet, Address, baseUrl: "/api/codex/v1", Container.Name, timeoutOverride); + return new Http(log, timeSet, Address, baseUrl: "/api/codex/v1", Container.Name); } } } diff --git a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs index 4320aa0..93c8f21 100644 --- a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs +++ b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs @@ -167,7 +167,6 @@ namespace DistTestCore.Helpers public class Pair { - private readonly TimeSpan timeout = TimeSpan.FromSeconds(60); private TimeSpan aToBTime = TimeSpan.FromSeconds(0); private TimeSpan bToATime = TimeSpan.FromSeconds(0); @@ -235,7 +234,7 @@ namespace DistTestCore.Helpers try { - var response = a.Node.GetDebugPeer(peerId, timeout); + var response = a.Node.GetDebugPeer(peerId); if (!response.IsPeerFound) { return PeerConnectionState.NoConnection; diff --git a/DistTestCore/Http.cs b/DistTestCore/Http.cs index f20c315..391dbc7 100644 --- a/DistTestCore/Http.cs +++ b/DistTestCore/Http.cs @@ -13,16 +13,14 @@ namespace DistTestCore private readonly Address address; private readonly string baseUrl; private readonly string? logAlias; - private readonly TimeSpan? timeoutOverride; - public Http(BaseLog log, ITimeSet timeSet, Address address, string baseUrl, string? logAlias = null, TimeSpan? timeoutOverride = null) + public Http(BaseLog log, ITimeSet timeSet, Address address, string baseUrl, string? logAlias = null) { this.log = log; this.timeSet = timeSet; this.address = address; this.baseUrl = baseUrl; this.logAlias = logAlias; - this.timeoutOverride = timeoutOverride; if (!this.baseUrl.StartsWith("/")) this.baseUrl = "/" + this.baseUrl; if (!this.baseUrl.EndsWith("/")) this.baseUrl += "/"; } @@ -127,24 +125,13 @@ namespace DistTestCore private T Retry(Func operation, string description) { - return Time.Retry(operation, GetTimeout(), timeSet.HttpCallRetryDelay(), description); + return Time.Retry(operation, timeSet.HttpCallRetryTime(), timeSet.HttpCallRetryDelay(), description); } private HttpClient GetClient() - { - return GetClient(GetTimeout()); - } - - private TimeSpan GetTimeout() - { - if (timeoutOverride.HasValue) return timeoutOverride.Value; - return timeSet.HttpCallTimeout(); - } - - private HttpClient GetClient(TimeSpan timeout) { var client = new HttpClient(); - client.Timeout = timeout; + client.Timeout = timeSet.HttpCallTimeout(); return client; } } diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index cd37fb4..1054d3e 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -12,7 +12,6 @@ namespace DistTestCore string GetName(); CodexDebugResponse GetDebugInfo(); CodexDebugPeerResponse GetDebugPeer(string peerId); - CodexDebugPeerResponse GetDebugPeer(string peerId, TimeSpan timeout); ContentId UploadFile(TestFile file); TestFile? DownloadContent(ContentId contentId, string fileLabel = ""); void ConnectToPeer(IOnlineCodexNode node); @@ -60,11 +59,6 @@ namespace DistTestCore return CodexAccess.GetDebugPeer(peerId); } - public CodexDebugPeerResponse GetDebugPeer(string peerId, TimeSpan timeout) - { - return CodexAccess.GetDebugPeer(peerId, timeout); - } - public ContentId UploadFile(TestFile file) { using var fileStream = File.OpenRead(file.Filename); diff --git a/DistTestCore/Timing.cs b/DistTestCore/Timing.cs index a653ce2..bd385ae 100644 --- a/DistTestCore/Timing.cs +++ b/DistTestCore/Timing.cs @@ -10,7 +10,7 @@ namespace DistTestCore public interface ITimeSet { TimeSpan HttpCallTimeout(); - TimeSpan HttpCallRetryTimeout(); + TimeSpan HttpCallRetryTime(); TimeSpan HttpCallRetryDelay(); TimeSpan WaitForK8sServiceDelay(); TimeSpan K8sOperationTimeout(); @@ -24,7 +24,7 @@ namespace DistTestCore return TimeSpan.FromSeconds(10); } - public TimeSpan HttpCallRetryTimeout() + public TimeSpan HttpCallRetryTime() { return TimeSpan.FromMinutes(1); } @@ -57,7 +57,7 @@ namespace DistTestCore return TimeSpan.FromHours(2); } - public TimeSpan HttpCallRetryTimeout() + public TimeSpan HttpCallRetryTime() { return TimeSpan.FromHours(5); }