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/09/01 10:42:16 UTC

[ignite-3] branch main updated: IGNITE-20288 .NET: Fix TestDroppedConnectionsAreRestoredInBackground flakiness (#2533)

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 f189bf979b IGNITE-20288 .NET: Fix TestDroppedConnectionsAreRestoredInBackground flakiness (#2533)
f189bf979b is described below

commit f189bf979b88a3607305e265eeee9134f582c377
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Fri Sep 1 13:42:11 2023 +0300

    IGNITE-20288 .NET: Fix TestDroppedConnectionsAreRestoredInBackground flakiness (#2533)
    
    * Increase timeout to fix flakiness
    * Extract common method to wait for background client connections and reuse in all tests
---
 .../Apache.Ignite.Tests/BasicAuthenticatorTests.cs |  3 +-
 .../Compute/ComputeClusterAwarenessTests.cs        |  8 ++---
 .../Apache.Ignite.Tests/Compute/ComputeTests.cs    |  4 +--
 .../Apache.Ignite.Tests/IgniteClientExtensions.cs  | 36 ++++++++++++++++++++++
 .../dotnet/Apache.Ignite.Tests/LoggingTests.cs     |  2 +-
 .../Apache.Ignite.Tests/PartitionAwarenessTests.cs |  3 +-
 .../dotnet/Apache.Ignite.Tests/ReconnectTests.cs   | 14 +++------
 .../Apache.Ignite.Tests/RequestBalancingTests.cs   |  4 +--
 8 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/BasicAuthenticatorTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/BasicAuthenticatorTests.cs
index 8a98732cd2..4eb2cace3f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/BasicAuthenticatorTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/BasicAuthenticatorTests.cs
@@ -112,8 +112,7 @@ public class BasicAuthenticatorTests : IgniteTestsBase
         }
 
         // Wait for the server to apply the configuration change and drop the client connection.
-        // ReSharper disable once AccessToDisposedClosure
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 0, 3000);
+        client.WaitForConnections(0, 3000);
 
         _authnEnabled = enable;
     }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeClusterAwarenessTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeClusterAwarenessTests.cs
index ee3e78a8b1..7b1fede7cc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeClusterAwarenessTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeClusterAwarenessTests.cs
@@ -43,9 +43,7 @@ namespace Apache.Ignite.Tests.Compute
             };
 
             using var client = await IgniteClient.StartAsync(clientCfg);
-
-            // ReSharper disable once AccessToDisposedClosure
-            TestUtils.WaitForCondition(() => client.GetConnections().Count == 3, 5000);
+            client.WaitForConnections(3);
 
             var res2 = await client.Compute.ExecuteAsync<string>(
                 new[] { server2.Node }, Array.Empty<DeploymentUnit>(), jobClassName: string.Empty);
@@ -100,9 +98,7 @@ namespace Apache.Ignite.Tests.Compute
             };
 
             using var client = await IgniteClient.StartAsync(clientCfg);
-
-            // ReSharper disable once AccessToDisposedClosure
-            TestUtils.WaitForCondition(() => client.GetConnections().Count == 2, 5000);
+            client.WaitForConnections(2);
 
             var nodeNames = new HashSet<string>();
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
index ec60c78aed..46f33b80d0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Compute/ComputeTests.cs
@@ -247,9 +247,7 @@ namespace Apache.Ignite.Tests.Compute
         {
             var proxies = GetProxies();
             using var client = await IgniteClient.StartAsync(GetConfig(proxies));
-
-            // ReSharper disable once AccessToDisposedClosure
-            TestUtils.WaitForCondition(() => client.GetConnections().Count == proxies.Count);
+            client.WaitForConnections(proxies.Count);
 
             var keyTuple = new IgniteTuple { [KeyCol] = key };
             var resNodeName = await client.Compute.ExecuteColocatedAsync<string>(TableName, keyTuple, Units, NodeNameJob);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteClientExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteClientExtensions.cs
new file mode 100644
index 0000000000..1f32a30cc0
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteClientExtensions.cs
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Tests;
+
+/// <summary>
+/// Extensions for <see cref="IIgniteClient"/>.
+/// </summary>
+public static class IgniteClientExtensions
+{
+    /// <summary>
+    /// Waits for the specified number of connections to be established. Throws an exception if the condition is not reached.
+    /// </summary>
+    /// <param name="client">Client.</param>
+    /// <param name="count">Connection count.</param>
+    /// <param name="timeoutMs">Timeout.</param>
+    public static void WaitForConnections(this IIgniteClient client, int count, int timeoutMs = 5000) =>
+        TestUtils.WaitForCondition(
+            condition: () => client.GetConnections().Count == count,
+            timeoutMs: timeoutMs,
+            messageFactory: () => $"Connection count: expected = {count}, actual = {client.GetConnections().Count}");
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/LoggingTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/LoggingTests.cs
index e3d49bdaa9..22cdf6827d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/LoggingTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/LoggingTests.cs
@@ -42,7 +42,7 @@ public class LoggingTests
         using var servers = FakeServerGroup.Create(3);
         using (var client = await servers.ConnectClientAsync(cfg))
         {
-            TestUtils.WaitForCondition(() => client.GetConnections().Count == 3);
+            client.WaitForConnections(3);
 
             await client.Tables.GetTablesAsync();
             await client.Sql.ExecuteAsync(null, "select 1");
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
index 90cd86d27f..4cc45ffde5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/PartitionAwarenessTests.cs
@@ -390,8 +390,7 @@ public class PartitionAwarenessTests
         };
 
         var client = await IgniteClient.StartAsync(cfg);
-
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 2);
+        client.WaitForConnections(2);
 
         return client;
     }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/ReconnectTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/ReconnectTests.cs
index e5212a4b08..23b22e563f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/ReconnectTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/ReconnectTests.cs
@@ -92,16 +92,16 @@ public class ReconnectTests
         using var servers = FakeServerGroup.Create(10);
         using var client = await servers.ConnectClientAsync(cfg);
 
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 10, 3000);
+        client.WaitForConnections(10);
         servers.DropNewConnections = true;
         servers.DropExistingConnections();
 
         // Dropped connections are detected by heartbeat.
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 0, 3000);
+        client.WaitForConnections(0);
 
         // Connections are restored in background due to ReconnectInterval.
         servers.DropNewConnections = false;
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 10, 3000);
+        client.WaitForConnections(10);
 
         Assert.DoesNotThrowAsync(async () => await client.Tables.GetTablesAsync());
     }
@@ -122,7 +122,7 @@ public class ReconnectTests
         servers.DropNewConnections = false;
 
         // When all servers are back online, connections are established in background due to ReconnectInterval.
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 5, 3000);
+        client.WaitForConnections(5);
 
         Assert.DoesNotThrowAsync(async () => await client.Tables.GetTablesAsync());
     }
@@ -163,10 +163,6 @@ public class ReconnectTests
 
         // All connections are restored.
         logger.Debug("Waiting for all connections to be restored...");
-
-        TestUtils.WaitForCondition(
-            () => client.GetConnections().Count == 10,
-            5000,
-            () => "Actual connection count: " + client.GetConnections().Count);
+        client.WaitForConnections(10);
     }
 }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/RequestBalancingTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/RequestBalancingTests.cs
index 7b092f33da..8f88d6065d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/RequestBalancingTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/RequestBalancingTests.cs
@@ -41,9 +41,7 @@ public class RequestBalancingTests
         };
 
         using var client = await IgniteClient.StartAsync(clientCfg);
-
-        // ReSharper disable once AccessToDisposedClosure
-        TestUtils.WaitForCondition(() => client.GetConnections().Count == 3, 5000);
+        client.WaitForConnections(3);
 
         for (var i = 0; i < 10; i++)
         {