mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-04 06: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()
|
private HttpClient GetClient()
|
||||||
{
|
{
|
||||||
var client = new HttpClient();
|
return HttpClientSingleton.Get(timeSet.HttpCallTimeout(), onClientCreated);
|
||||||
client.Timeout = timeSet.HttpCallTimeout();
|
}
|
||||||
onClientCreated(client);
|
}
|
||||||
return client;
|
|
||||||
|
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 NUnit.Framework;
|
||||||
using Utils;
|
using Utils;
|
||||||
|
|
||||||
namespace CodexReleaseTests.DataTests
|
namespace CodexReleaseTests.DataTests.DHT
|
||||||
{
|
{
|
||||||
[Ignore("work in progress")]
|
[Ignore("work in progress")]
|
||||||
[TestFixture(10, 10000)]
|
[TestFixture(10, 1000)]
|
||||||
[TestFixture(50, 1000)]
|
[TestFixture(50, 1000)]
|
||||||
[TestFixture(100, 1000)]
|
[TestFixture(10, 10000)]
|
||||||
|
[TestFixture(20, 10000)]
|
||||||
|
[TestFixture(30, 10000)]
|
||||||
|
[TestFixture(50, 10000)]
|
||||||
public class DhtTest : AutoBootstrapDistTest
|
public class DhtTest : AutoBootstrapDistTest
|
||||||
{
|
{
|
||||||
public DhtTest(int nodes, int files)
|
public DhtTest(int nodes, int files)
|
||||||
@ -50,7 +53,6 @@ namespace CodexReleaseTests.DataTests
|
|||||||
node.DownloadContent(cids.PickOneRandom());
|
node.DownloadContent(cids.PickOneRandom());
|
||||||
});
|
});
|
||||||
|
|
||||||
Log(Time.FormatDuration(timing));
|
|
||||||
Assert.That(timing, Is.LessThan(maxDownloadDuration));
|
Assert.That(timing, Is.LessThan(maxDownloadDuration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user