googleapis / python-spanner

Apache License 2.0
135 stars 85 forks source link

Flaky test in DBAPI test_multiple_aborts_in_transaction #1087

Open harshachinta opened 8 months ago

harshachinta commented 8 months ago

The below test in DBAPI appears to be flaky. The test is failing in presubmit builds randomly and a rebuild fixes the issue.

=================================== FAILURES ===================================
________________ TestDbApi.test_multiple_aborts_in_transaction _________________

self = <tests.system.test_dbapi.TestDbApi object at 0x7f9a357654f0>
dbapi_database = <google.cloud.spanner_v1.testing.database_test.TestDatabase object at 0x7f9a352176a0>

    def test_multiple_aborts_in_transaction(self, dbapi_database):
        """Test that when there are multiple Abort exceptions in a transaction
        on different statements, then the retry succeeds."""

        method_count_interceptor = dbapi_database._method_count_interceptor
        method_count_interceptor.reset()
        # called 3 times
        self._insert_row(1)
        dbapi_database._method_abort_interceptor.set_method_to_abort(
            EXECUTE_STREAMING_SQL_METHOD, self._conn
        )
        # called 3 times
        self._cursor.execute("SELECT * FROM contacts")
        dbapi_database._method_abort_interceptor.reset()
        self._cursor.fetchall()
        # called 2 times
        self._insert_row(2)
        # called 2 times
        self._cursor.execute("SELECT * FROM contacts")
        self._cursor.fetchone()
        dbapi_database._method_abort_interceptor.set_method_to_abort(
            COMMIT_METHOD, self._conn
        )
        # called 2 times
        self._conn.commit()
        dbapi_database._method_abort_interceptor.reset()
        assert method_count_interceptor._counts[COMMIT_METHOD] == 2
>       assert method_count_interceptor._counts[EXECUTE_STREAMING_SQL_METHOD] == 10
E       assert 13 == 10

[tests/system/test_dbapi.py:854](https://cs.corp.google.com/piper///depot/google3/tests/system/test_dbapi.py?l=854): AssertionError
harshachinta commented 8 months ago

@ankiaga Feel free to pick this up based on your priorities. I had to rebuild the presubmits couple of times to get this passing.