mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-02 05:23:09 +00:00
singletons HTTP client
This commit is contained in:
parent
72e5a1995d
commit
cfe2c47d95
@ -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<TimeSpan, HttpClient> instances = new();
|
||||
|
||||
public static HttpClient Get(TimeSpan timeout, Action<HttpClient> onClientCreated)
|
||||
{
|
||||
if (!instances.ContainsKey(timeout))
|
||||
{
|
||||
var client = new HttpClient();
|
||||
client.Timeout = timeout;
|
||||
onClientCreated(client);
|
||||
instances.Add(timeout, client);
|
||||
}
|
||||
|
||||
return instances[timeout];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user