Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_keyspace might flaky (causing a test to be flaky) #302

Open
fruch opened this issue Feb 28, 2024 · 0 comments
Open

set_keyspace might flaky (causing a test to be flaky) #302

fruch opened this issue Feb 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fruch
Copy link

fruch commented Feb 28, 2024

test_can_register_udt_before_connecting was flaky for a long time

we've pinpoint it to be the usage of set_keyspace
and in #299 we stop using set_keyspace

this is the test before the change, for reference:

    def test_can_register_udt_before_connecting(self):
        """
        Test the registration of UDTs before session creation
        """
        c = TestCluster()
        s = c.connect(wait_for_all_pools=True)
        s.execute("""
            CREATE KEYSPACE udt_test_register_before_connecting
            WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }
            """)
        s.set_keyspace("udt_test_register_before_connecting")
        s.execute("CREATE TYPE user (age int, name text)")
        s.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)")

        s.execute("""
            CREATE KEYSPACE udt_test_register_before_connecting2
            WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }
            """)
        s.set_keyspace("udt_test_register_before_connecting2")
        s.execute("CREATE TYPE user (state text, is_cool boolean)")
        s.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<user>)")

        # now that types are defined, shutdown and re-create Cluster
        c.shutdown()
        c = TestCluster()
        User1 = namedtuple('user', ('age', 'name'))
        User2 = namedtuple('user', ('state', 'is_cool'))
        c.register_user_type("udt_test_register_before_connecting", "user", User1)
        c.register_user_type("udt_test_register_before_connecting2", "user", User2)

        s = c.connect(wait_for_all_pools=True)

        s.set_keyspace("udt_test_register_before_connecting")
        s.execute("INSERT INTO mytable (a, b) VALUES (%s, %s)", (0, User1(42, 'bob')))
        result = s.execute("SELECT b FROM mytable WHERE a=0")
        row = result[0]
        self.assertEqual(42, row.b.age)
        self.assertEqual('bob', row.b.name)
        self.assertTrue(type(row.b) is User1)

        # use the same UDT name in a different keyspace
        s.set_keyspace("udt_test_register_before_connecting2")
        s.execute("INSERT INTO mytable (a, b) VALUES (%s, %s)", (0, User2('Texas', True)))
        result = s.execute("SELECT b FROM mytable WHERE a=0")
        row = result[0]
        self.assertEqual('Texas', row.b.state)
        self.assertEqual(True, row.b.is_cool)
        self.assertTrue(type(row.b) is User2)
        s.execute("DROP KEYSPACE udt_test_register_before_connecting")
        s.execute("DROP KEYSPACE udt_test_register_before_connecting2")

the hypophysis I have, is that some connection (of some shard) might have been missed, and didn't got the USE command,
we don't have a mechanism to validate all connect got it, and that the next query can't be executed before they did

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant