Make CanUseTorClient more reliable

This commit is contained in:
nicolas.dorier 2022-01-25 12:27:44 +09:00
parent e917796fce
commit 74037fd605
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE

View File

@ -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)]