-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathTimeoutsApplyDuringHandShake.cs
More file actions
80 lines (75 loc) · 4.37 KB
/
TimeoutsApplyDuringHandShake.cs
File metadata and controls
80 lines (75 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using FluentAssertions;
using Halibut.Tests.Builders;
using Halibut.Tests.Support;
using Halibut.Tests.Support.TestAttributes;
using Halibut.Tests.Support.TestCases;
using Halibut.Tests.TestServices.Async;
using Halibut.Tests.Util;
using Halibut.TestUtils.Contracts;
using NUnit.Framework;
using Octopus.TestPortForwarder;
namespace Halibut.Tests.Timeouts
{
/// <summary>
/// Where handshake means early on in setting up a TCP connection.
/// </summary>
public class TimeoutsApplyDuringHandShake : BaseTest
{
[Test]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testWebSocket: false, additionalParameters: new object[] { true, 1 })]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testWebSocket: false, additionalParameters: new object[] { false, 1 })]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testWebSocket: false, additionalParameters: new object[] { true, 2 })]
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false, testWebSocket: false, additionalParameters: new object[] { false, 2 })]
public async Task WhenTheFirstWriteOverTheWireOccursOnAConnectionThatImmediatelyPauses_AWriteTimeoutShouldApply(
ClientAndServiceTestCase clientAndServiceTestCase,
bool onClientToOrigin, // Don't dwell on what this means, we just want to test all combinations of where the timeout can occur.
int writeNumberToPauseOn // Ie pause on the first or second write
)
{
var dataTransferObserverPauser = new DataTransferObserverBuilder()
.WithWritePausing(Logger, writeNumberToPauseOn)
.Build();
var dataTransferObserverDoNothing = new DataTransferObserverBuilder().Build();
await using (var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder()
.As<LatestClientAndLatestServiceBuilder>()
.WithPortForwarding(port => PortForwarderUtil.ForwardingToLocalPort(port)
.WithDataObserver(() =>
{
if(onClientToOrigin) return new BiDirectionalDataTransferObserver(dataTransferObserverPauser,dataTransferObserverDoNothing);
return new BiDirectionalDataTransferObserver(dataTransferObserverDoNothing, dataTransferObserverPauser);
})
.Build())
.WithPendingRequestQueueFactory(logFactory => new FuncPendingRequestQueueFactory(uri => new PendingRequestQueueBuilder()
.WithLog(logFactory.ForEndpoint(uri))
.WithPollingQueueWaitTimeout(TimeSpan.FromSeconds(1))
.Build()))
.WithEchoService()
.Build(CancellationToken))
{
var echo = clientAndService.CreateAsyncClient<IEchoService, IAsyncClientEchoService>(IncreasePollingQueueTimeout);
var sw = Stopwatch.StartNew();
try
{
await echo.SayHelloAsync("Make a request to make sure the connection is running, and ready. Lets not measure SSL setup cost.");
}
catch (Exception e)
{
Logger.Information(e, "An exception was raised during the request, this is not an issue since we are concerned about the timings. " +
"Exceptions only occur occasionally and probably only on listening.");
}
sw.Stop();
sw.Elapsed.Should().BeCloseTo(clientAndService.Service.TimeoutsAndLimits.TcpClientAuthenticationSendTimeout, TimeSpan.FromSeconds(15), "Since a paused connection early on should not hang forever.");
await echo.SayHelloAsync("The pump wont be paused here so this should work.");
}
}
static void IncreasePollingQueueTimeout(ServiceEndPoint point)
{
// We don't want to measure the polling queue timeouts.
point.PollingRequestMaximumMessageProcessingTimeout = TimeSpan.FromMinutes(10);
point.PollingRequestQueueTimeout = TimeSpan.FromMinutes(10);
}
}
}