diff --git a/Framework/WebUtils/Http.cs b/Framework/WebUtils/Http.cs index e4931996..02b7cb57 100644 --- a/Framework/WebUtils/Http.cs +++ b/Framework/WebUtils/Http.cs @@ -79,10 +79,25 @@ namespace WebUtils private HttpClient GetClient() { - var client = new HttpClient(); - client.Timeout = timeSet.HttpCallTimeout(); - onClientCreated(client); - return client; + return HttpClientSingleton.Get(timeSet.HttpCallTimeout(), onClientCreated); + } + } + + public static class HttpClientSingleton + { + private static readonly Dictionary instances = new(); + + public static HttpClient Get(TimeSpan timeout, Action onClientCreated) + { + if (!instances.ContainsKey(timeout)) + { + var client = new HttpClient(); + client.Timeout = timeout; + onClientCreated(client); + instances.Add(timeout, client); + } + + return instances[timeout]; } } } diff --git a/Tests/CodexReleaseTests/DataTests/DhtTest.cs b/Tests/CodexReleaseTests/DataTests/DhtTest.cs index 8b47a63e..e4a99b8e 100644 --- a/Tests/CodexReleaseTests/DataTests/DhtTest.cs +++ b/Tests/CodexReleaseTests/DataTests/DhtTest.cs @@ -4,12 +4,15 @@ using Logging; using NUnit.Framework; using Utils; -namespace CodexReleaseTests.DataTests +namespace CodexReleaseTests.DataTests.DHT { [Ignore("work in progress")] - [TestFixture(10, 10000)] + [TestFixture(10, 1000)] [TestFixture(50, 1000)] - [TestFixture(100, 1000)] + [TestFixture(10, 10000)] + [TestFixture(20, 10000)] + [TestFixture(30, 10000)] + [TestFixture(50, 10000)] public class DhtTest : AutoBootstrapDistTest { public DhtTest(int nodes, int files) @@ -50,7 +53,6 @@ namespace CodexReleaseTests.DataTests node.DownloadContent(cids.PickOneRandom()); }); - Log(Time.FormatDuration(timing)); Assert.That(timing, Is.LessThan(maxDownloadDuration)); } }