This is an automated email from the ASF dual-hosted git repository.

bereng pushed a commit to branch cassandra-5.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-5.0 by this push:
     new 52a8d2947a Flaky test: 
org.apache.cassandra.cql3.validation.operations.InsertUpdateIfConditionTest
52a8d2947a is described below

commit 52a8d2947a7509baec05a5b6f6c1377219e3a051
Author: Bereng <[email protected]>
AuthorDate: Tue Aug 29 10:53:09 2023 +0200

    Flaky test: 
org.apache.cassandra.cql3.validation.operations.InsertUpdateIfConditionTest
    
    patch by Berenguer Blasi; reviewed by Andres de la Peña for CASSANDRA-18393
---
 src/java/org/apache/cassandra/gms/Gossiper.java    | 13 +----
 .../operations/InsertUpdateIfConditionTest.java    | 57 ++++++++++------------
 2 files changed, 28 insertions(+), 42 deletions(-)

diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java 
b/src/java/org/apache/cassandra/gms/Gossiper.java
index 5f104673d1..5f90b2f2c4 100644
--- a/src/java/org/apache/cassandra/gms/Gossiper.java
+++ b/src/java/org/apache/cassandra/gms/Gossiper.java
@@ -2484,21 +2484,12 @@ public class Gossiper implements 
IFailureDetectionEventListener, GossiperMBean
      * Returns {@code true} if there are nodes on version lower than the 
provided version
      */
     public boolean isUpgradingFromVersionLowerThan(CassandraVersion 
referenceVersion)
-    {
-        return isUpgradingFromVersionLowerThanC17653(referenceVersion).left;
-    }
-
-    /* TODO: Aux method for debug purposes on fixing C17653. To be removed*/
-    @VisibleForTesting
-    public Pair<Boolean, CassandraVersion> 
isUpgradingFromVersionLowerThanC17653(CassandraVersion referenceVersion)
     {
         CassandraVersion v = upgradeFromVersionMemoized.get();
         if (CassandraVersion.NULL_VERSION.equals(v) && scheduledGossipTask == 
null)
-            return Pair.create(false, v);
-
-        boolean res = v != null && v.compareTo(referenceVersion) < 0;
+            return false;
 
-        return Pair.create(res, v);
+        return v != null && v.compareTo(referenceVersion) < 0;
     }
 
     private boolean nodesAgreeOnSchema(Collection<InetAddressAndPort> nodes)
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
index 531c1f6c02..c57f61d6eb 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertUpdateIfConditionTest.java
@@ -37,7 +37,6 @@ import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.schema.SchemaConstants;
 import org.apache.cassandra.schema.SchemaKeyspaceTables;
 import org.apache.cassandra.utils.CassandraVersion;
-import org.apache.cassandra.utils.Pair;
 
 import static java.lang.String.format;
 import static org.junit.Assert.assertEquals;
@@ -64,18 +63,14 @@ public class InsertUpdateIfConditionTest extends CQLTester
     {
         ServerTestUtils.daemonInitialization();
         return Arrays.asList(new Object[]{ "3.0", (Runnable) () -> {
-                                 Pair<Boolean, CassandraVersion> res = 
Gossiper.instance.isUpgradingFromVersionLowerThanC17653(new 
CassandraVersion("3.11"));
-                                 assertTrue(debugMsgCASSANDRA17653(res), 
res.left);
+                                 
assertTrue(Gossiper.instance.isUpgradingFromVersionLowerThan(new 
CassandraVersion("3.11")));
                              } },
                              new Object[]{ "3.11", (Runnable) () -> {
-                                 Pair<Boolean, CassandraVersion> res = 
Gossiper.instance.isUpgradingFromVersionLowerThanC17653(SystemKeyspace.CURRENT_VERSION);
-                                 assertTrue(debugMsgCASSANDRA17653(res), 
res.left);
-                                 res = 
Gossiper.instance.isUpgradingFromVersionLowerThanC17653(new 
CassandraVersion("3.11"));
-                                 assertFalse(debugMsgCASSANDRA17653(res), 
res.left);
+                                 
assertTrue(Gossiper.instance.isUpgradingFromVersionLowerThan(SystemKeyspace.CURRENT_VERSION));
+                                 
assertFalse(Gossiper.instance.isUpgradingFromVersionLowerThan(new 
CassandraVersion("3.11")));
                              } },
                              new Object[]{ 
SystemKeyspace.CURRENT_VERSION.toString(), (Runnable) () -> {
-                                 Pair<Boolean, CassandraVersion> res = 
Gossiper.instance.isUpgradingFromVersionLowerThanC17653(SystemKeyspace.CURRENT_VERSION);
-                                 assertFalse(debugMsgCASSANDRA17653(res), 
res.left);
+                                 
assertFalse(Gossiper.instance.isUpgradingFromVersionLowerThan(SystemKeyspace.CURRENT_VERSION));
                              } });
     }
 
@@ -93,8 +88,14 @@ public class InsertUpdateIfConditionTest extends CQLTester
     
     public static void beforeSetup(String clusterMinVersion, Runnable 
assertion)
     {
-        Util.setUpgradeFromVersion(clusterMinVersion);
-        assertion.run();
+        // setUpgradeFromVersion adds node2 to the Gossiper. On slow CI envs 
the Gossiper might auto-remove it after some
+        // timeout if it thinks it's a fat client making the test fail. Just 
retry C18393.
+        Util.spinAssertEquals(Boolean.TRUE, () -> {
+            Util.setUpgradeFromVersion(clusterMinVersion);
+            assertion.run();
+            return true;
+        },
+                              5);
     }
 
     @AfterClass
@@ -107,7 +108,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
      * Migrated from cql_tests.py:TestCQL.cas_simple_test()
      */
     @Test
-    public void testSimpleCas() throws Throwable
+    public void testSimpleCas()
     {
         createTable("CREATE TABLE %s (tkn int, consumed boolean, PRIMARY KEY 
(tkn))");
 
@@ -178,7 +179,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
         assertRows(execute("DELETE v2 FROM %s WHERE k = 0 IF v1 = ?", 5), 
row(true));
         assertRows(execute("SELECT * FROM %s"), row(0, 5, null, null));
 
-        // Shouln't apply
+        // Shouldn't apply
         assertRows(execute("DELETE v1 FROM %s WHERE k = 0 IF v3 = ?", 4), 
row(false, null));
 
         // Should apply
@@ -365,14 +366,14 @@ public class InsertUpdateIfConditionTest extends CQLTester
         Thread.sleep(1001);
         assertRows(execute("UPDATE %s SET v = 1 WHERE k = 0 IF lock = null"),
                    row(true));
-    } 
+    }
 
     /**
      * Test for 7499,
      * migrated from cql_tests.py:TestCQL.cas_and_list_index_test()
      */
     @Test
-    public void testCasAndListIndex() throws Throwable
+    public void testCasAndListIndex()
     {
         createTable("CREATE TABLE %s ( k int PRIMARY KEY, v text, l 
list<text>)");
 
@@ -429,7 +430,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
     public void testDropCreateTableIfNotExists() throws Throwable
     {
         String tableName = createTableName();
-        String fullTableName = KEYSPACE + "." + tableName;
+        String fullTableName = KEYSPACE + '.' + tableName;
 
         // try dropping when doesn't exist
         schemaChange("DROP TABLE IF EXISTS " + fullTableName);
@@ -456,7 +457,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
      * Migrated from cql_tests.py:TestCQL.conditional_ddl_index_test()
      */
     @Test
-    public void testDropCreateIndexIfNotExists() throws Throwable
+    public void testDropCreateIndexIfNotExists()
     {
         String tableName = createTable("CREATE TABLE %s (id text PRIMARY KEY, 
value1 blob, value2 blob)with comment = 'foo'");
 
@@ -484,7 +485,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
     {
         execute("use " + KEYSPACE);
 
-        // try dropping when doesn 't exist
+        // try dropping when doesn't exist
         execute("DROP TYPE IF EXISTS mytype");
 
         // create and confirm
@@ -544,7 +545,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
     }
 
     @Test
-    public void testConditionalUpdatesWithNullValues() throws Throwable
+    public void testConditionalUpdatesWithNullValues()
     {
         createTable("CREATE TABLE %s (a int, b int, s int static, d int, 
PRIMARY KEY (a, b))");
 
@@ -616,7 +617,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
     }
 
     @Test
-    public void testConditionalUpdatesWithNullValuesWithBatch() throws 
Throwable
+    public void testConditionalUpdatesWithNullValuesWithBatch()
     {
         createTable("CREATE TABLE %s (a int, b int, s int static, d text, 
PRIMARY KEY (a, b))");
 
@@ -731,7 +732,7 @@ public class InsertUpdateIfConditionTest extends CQLTester
     }
 
     @Test
-    public void testConditionalDeleteWithNullValues() throws Throwable
+    public void testConditionalDeleteWithNullValues()
     {
         createTable("CREATE TABLE %s (a int, b int, s1 int static, s2 int 
static, v int, PRIMARY KEY (a, b))");
 
@@ -857,8 +858,8 @@ public class InsertUpdateIfConditionTest extends CQLTester
         // As all statement gets the same timestamp, the biggest value ends up 
winning, so that's "foo"
         assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, "foo", 
null));
 
-        // Multiple deletes on the same row with exists conditions (note that 
this is somewhat non-sensical, one of the
-        // delete is redundant, we're just checking it doesn't break something)
+        // Multiple deletes on the same row with exists conditions (note that 
this is somewhat none-sensical, one of the
+        // deletes is redundant, we're just checking it doesn't break 
something)
         assertRows(execute("BEGIN BATCH "
                            + "DELETE FROM %1$s WHERE k = 0 IF EXISTS; "
                            + "DELETE FROM %1$s WHERE k = 0 IF EXISTS; "
@@ -909,8 +910,8 @@ public class InsertUpdateIfConditionTest extends CQLTester
         // As all statement gets the same timestamp, the biggest value ends up 
winning, so that's "foo"
         assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, 0, "foo", 
null));
 
-        // Multiple deletes on the same row with exists conditions (note that 
this is somewhat non-sensical, one of the
-        // delete is redundant, we're just checking it doesn't break something)
+        // Multiple deletes on the same row with exists conditions (note that 
this is somewhat none-sensical, one of the
+        // deletes is redundant, we're just checking it doesn't break 
something)
         assertRows(execute("BEGIN BATCH "
                            + "DELETE FROM %1$s WHERE k = 0 AND t = 0 IF 
EXISTS; "
                            + "DELETE FROM %1$s WHERE k = 0 AND t = 0 IF 
EXISTS; "
@@ -964,10 +965,4 @@ public class InsertUpdateIfConditionTest extends CQLTester
 
         assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, 
Duration.from("10s"), 6));
     }
-
-    // Helper to debug on the next occurrence of CASSANDRA-17653
-    private static String debugMsgCASSANDRA17653(Pair<Boolean, 
CassandraVersion> res)
-    {
-        return("Failed on Cass Version: " + res.right == null ? "null" : 
res.right + " boolean:" + res.left);
-    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to