mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
Make CanUseTorClient more reliable
This commit is contained in:
parent
e917796fce
commit
74037fd605
@ -650,25 +650,38 @@ namespace BTCPayServer.Tests
|
||||
|
||||
TestLogs.LogInformation("Querying a tor website");
|
||||
response = await client.GetAsync("http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
Assert.Contains("Bitcoin", result);
|
||||
if (response.IsSuccessStatusCode) // Sometimes the site goes down
|
||||
{
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
Assert.Contains("Bitcoin", result);
|
||||
}
|
||||
|
||||
TestLogs.LogInformation("...twice");
|
||||
response = await client.GetAsync("http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
client.Dispose();
|
||||
|
||||
TestLogs.LogInformation("...three times, but with a new httpclient");
|
||||
client = httpFactory.CreateClient(PayjoinServerCommunicator.PayjoinOnionNamedClient);
|
||||
response = await client.GetAsync("http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
TestLogs.LogInformation("Querying an onion address which can't be found");
|
||||
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync("http://dwoduwoi.onion/"));
|
||||
|
||||
|
||||
TestLogs.LogInformation("Querying valid onion but unreachable");
|
||||
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync("http://nzwsosflsoquxirwb2zikz6uxr3u5n5u73l33umtdx4hq5mzm5dycuqd.onion/"));
|
||||
using var cts = new CancellationTokenSource(10_000);
|
||||
try
|
||||
{
|
||||
await client.GetAsync("http://nzwsosflsoquxirwb2zikz6uxr3u5n5u73l33umtdx4hq5mzm5dycuqd.onion/", cts.Token);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
|
||||
}
|
||||
catch when (cts.Token.IsCancellationRequested) // Ignore timeouts
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Timeout = LongRunningTestTimeout)]
|
||||
|
Loading…
Reference in New Issue
Block a user