You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2023/07/03 16:03:25 UTC
[ignite-3] branch main updated: IGNITE-19808 .NET: Fix TestHandshakesFailedTimeout flakiness (#2277)
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new f12bbb07d5 IGNITE-19808 .NET: Fix TestHandshakesFailedTimeout flakiness (#2277)
f12bbb07d5 is described below
commit f12bbb07d5bb1f56cbd8eaffe77ab7c0369ba0eb
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Jul 3 19:03:20 2023 +0300
IGNITE-19808 .NET: Fix TestHandshakesFailedTimeout flakiness (#2277)
* Fix `TestBackgroundConnectionProcessDoesNotBlockOperations` to dispose the client properly: metric tags proved that it causes unrelated metrics updates while other tests run, and sometimes results in failing `TestHandshakesFailedTimeout`.
* Add some other minor test improvements.
---
.../Apache.Ignite.Tests/ClientFailoverSocketTests.cs | 8 ++++----
.../dotnet/Apache.Ignite.Tests/IgniteServerBase.cs | 4 ++++
.../platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs | 16 ++++++++++------
.../dotnet/Apache.Ignite/Internal/ClientSocket.cs | 12 ++++++------
4 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/ClientFailoverSocketTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/ClientFailoverSocketTests.cs
index fd6b1ee4a5..41f0a8ad60 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/ClientFailoverSocketTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/ClientFailoverSocketTests.cs
@@ -32,8 +32,8 @@ public class ClientFailoverSocketTests
{
ClientFailoverSocket.ResetGlobalEndpointIndex();
- var operationTimeout = TimeSpan.FromSeconds(1);
- var handshakeDelay = TimeSpan.FromSeconds(10);
+ var operationTimeout = TimeSpan.FromSeconds(0.5);
+ var handshakeDelay = TimeSpan.FromSeconds(2);
using var server1 = new FakeServer { HandshakeDelay = handshakeDelay };
using var server2 = new FakeServer();
@@ -44,8 +44,8 @@ public class ClientFailoverSocketTests
};
// First connection will go to server2, which does not have a delay.
- // Second connection will be established in background, and will take 10 seconds, but will not delay operations.
- var client = await IgniteClient.StartAsync(clientCfg).WaitAsync(operationTimeout);
+ // Second connection will be established in background, and will take 2 seconds, but will not delay operations.
+ using var client = await IgniteClient.StartAsync(clientCfg).WaitAsync(operationTimeout);
var tables = await client.Tables.GetTablesAsync().WaitAsync(operationTimeout);
Assert.AreEqual(0, tables.Count);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServerBase.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServerBase.cs
index 22caa3114b..961ba14280 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServerBase.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServerBase.cs
@@ -24,6 +24,7 @@ using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Internal.Buffers;
+using NUnit.Framework;
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Tests.")]
public abstract class IgniteServerBase : IDisposable
@@ -47,6 +48,9 @@ public abstract class IgniteServerBase : IDisposable
_listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
_listener.Listen(backlog: 1);
+
+ Console.WriteLine($"Fake server started [port={Port}, test={TestContext.CurrentContext.Test.Name}]");
+
Task.Run(ListenLoop);
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
index b819e47fb2..68abd724ed 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/MetricsTests.cs
@@ -34,7 +34,7 @@ using NUnit.Framework;
/// </summary>
public class MetricsTests
{
- private Listener _listener = null!;
+ private volatile Listener _listener = null!;
[SetUp]
public void SetUp() => _listener = new Listener();
@@ -57,6 +57,9 @@ public class MetricsTests
_listener.Dispose();
}
+ [OneTimeTearDown]
+ public void OneTimeTearDown() => _listener.Dispose();
+
[Test]
public async Task TestConnectionsMetrics()
{
@@ -65,11 +68,12 @@ public class MetricsTests
Assert.AreEqual(0, _listener.GetMetric("connections-established"));
Assert.AreEqual(0, _listener.GetMetric("connections-active"));
- var client = await server.ConnectClientAsync();
- Assert.AreEqual(1, _listener.GetMetric("connections-established"));
- Assert.AreEqual(1, _listener.GetMetric("connections-active"));
+ using (await server.ConnectClientAsync())
+ {
+ Assert.AreEqual(1, _listener.GetMetric("connections-established"));
+ Assert.AreEqual(1, _listener.GetMetric("connections-active"));
+ }
- client.Dispose();
Assert.AreEqual(0, _listener.GetMetric("connections-active"));
(await server.ConnectClientAsync()).Dispose();
@@ -136,7 +140,7 @@ public class MetricsTests
{
using var server = new FakeServer { SendInvalidMagic = true };
- Assert.ThrowsAsync<IgniteClientConnectionException>(async () => await server.ConnectClientAsync());
+ Assert.ThrowsAsync<IgniteClientConnectionException>(async () => await server.ConnectClientAsync(GetConfig()));
Assert.AreEqual(1, _listener.GetMetric("handshakes-failed"));
Assert.AreEqual(0, _listener.GetMetric("handshakes-failed-timeout"));
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
index 42dd3f8659..2f5ca0d455 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
@@ -213,12 +213,7 @@ namespace Apache.Ignite.Internal
}
catch (Exception e)
{
- logger?.Warn($"Connection failed before or during handshake [remoteAddress={socket.RemoteEndPoint}]: {e.Message}.", e);
-
- if (connected)
- {
- Metrics.ConnectionsActiveDecrement();
- }
+ logger?.Warn($"Connection failed before or during handshake [remoteAddress={endPoint.EndPoint}]: {e.Message}.", e);
if (e.GetBaseException() is TimeoutException)
{
@@ -232,6 +227,11 @@ namespace Apache.Ignite.Internal
// ReSharper disable once MethodHasAsyncOverload
socket.Dispose();
+ if (connected)
+ {
+ Metrics.ConnectionsActiveDecrement();
+ }
+
throw new IgniteClientConnectionException(
ErrorGroups.Client.Connection,
"Failed to connect to endpoint: " + endPoint.EndPoint,