From 872004ab9ce960a3a53b25262844cff75c9fba21 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 31 Oct 2019 13:04:26 -0400 Subject: [PATCH 1/4] test(spanner): unflake 'test_transaction_batch_update_and_execute_dml' systest Closes #9534. --- spanner/tests/system/test_system.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index a9d78fcdc2ff..ac54c298f132 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -24,6 +24,7 @@ import uuid import pytest +import grpc from google.rpc import code_pb2 from google.api_core import exceptions @@ -66,6 +67,10 @@ COUNTERS_TABLE = "counters" COUNTERS_COLUMNS = ("name", "value") +_STATUS_CODE_TO_GRPC_STATUS_CODE = { + member.value[0]: member for member in grpc.StatusCode +} + class Config(object): """Run-time configuration to be modified at set-up. @@ -787,7 +792,10 @@ def test_transaction_execute_update_then_insert_commit(self): @staticmethod def _check_batch_status(status_code): if status_code != code_pb2.OK: - raise exceptions.from_grpc_status(status_code, "batch_update failed") + grpc_status_code = _STATUS_CODE_TO_GRPC_STATUS_CODE[status_code] + call = FauxCall(status_code) + exc = exceptions.from_grpc_status( + grpc_status_code, "batch_update failed", errors=[call]) def test_transaction_batch_update_success(self): # [START spanner_test_dml_with_mutation] @@ -2190,3 +2198,22 @@ def _handle_abort_unit_of_work(self, transaction): def handle_abort(self, database): database.run_in_transaction(self._handle_abort_unit_of_work) self.handler_done.set() + + +class FauxCall(object): + + def __init__(self, code, details="FauxCall"): + self._code = code + self._details = details + + def initial_metadata(self): + return {} + + def trailing_metadata(self): + return {} + + def code(self): + return self._code + + def details(self): + return self._details From 3ffa5068d25add2be86f040bad151225d02aab46 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 31 Oct 2019 14:05:06 -0400 Subject: [PATCH 2/4] Blacken --- spanner/tests/system/test_system.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index ac54c298f132..4819bf360b6c 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -794,8 +794,9 @@ def _check_batch_status(status_code): if status_code != code_pb2.OK: grpc_status_code = _STATUS_CODE_TO_GRPC_STATUS_CODE[status_code] call = FauxCall(status_code) - exc = exceptions.from_grpc_status( - grpc_status_code, "batch_update failed", errors=[call]) + exc = exceptions.from_grpc_status( + grpc_status_code, "batch_update failed", errors=[call] + ) def test_transaction_batch_update_success(self): # [START spanner_test_dml_with_mutation] @@ -2201,7 +2202,6 @@ def handle_abort(self, database): class FauxCall(object): - def __init__(self, code, details="FauxCall"): self._code = code self._details = details From 1ed4645f0ed8533bee870bd7e5cfe1e9261989dc Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 31 Oct 2019 15:44:02 -0400 Subject: [PATCH 3/4] fix: thinko --- spanner/tests/system/test_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index 4819bf360b6c..dea0b6a6e130 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -794,7 +794,7 @@ def _check_batch_status(status_code): if status_code != code_pb2.OK: grpc_status_code = _STATUS_CODE_TO_GRPC_STATUS_CODE[status_code] call = FauxCall(status_code) - exc = exceptions.from_grpc_status( + raise exceptions.from_grpc_status( grpc_status_code, "batch_update failed", errors=[call] ) From f868cf2f111f0e37d5bd29959aa3b4b71ea45d77 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 31 Oct 2019 17:16:23 -0400 Subject: [PATCH 4/4] tests(spanner): harden 'test_transaction_batch_update_w_syntax_error' against partial success + abort. --- spanner/tests/system/test_system.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index dea0b6a6e130..abfd1297d7ce 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -790,8 +790,8 @@ def test_transaction_execute_update_then_insert_commit(self): # [END spanner_test_dml_with_mutation] @staticmethod - def _check_batch_status(status_code): - if status_code != code_pb2.OK: + def _check_batch_status(status_code, expected=code_pb2.OK): + if status_code != expected: grpc_status_code = _STATUS_CODE_TO_GRPC_STATUS_CODE[status_code] call = FauxCall(status_code) raise exceptions.from_grpc_status( @@ -915,7 +915,7 @@ def unit_of_work(transaction): status, row_counts = transaction.batch_update( [insert_statement, update_statement, delete_statement] ) - self.assertEqual(status.code, code_pb2.INVALID_ARGUMENT) + self._check_batch_status(status.code, code_pb2.INVALID_ARGUMENT) self.assertEqual(len(row_counts), 1) self.assertEqual(row_counts[0], 1)