From 4b726a985b18e28dbfad6738dc0450cd9076bf84 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Mon, 21 Dec 2020 15:12:43 -0800 Subject: [PATCH 1/8] fix: Convert PBs in system test cleanup --- tests/system/test_system.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 5bd42c5a9c..ca94e83ff1 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -35,11 +35,13 @@ from google.cloud.spanner_v1 import Type from google.cloud._helpers import UTC +from google.cloud.spanner_v1 import BurstyPool +from google.cloud.spanner_v1 import COMMIT_TIMESTAMP from google.cloud.spanner_v1 import Client from google.cloud.spanner_v1 import KeyRange from google.cloud.spanner_v1 import KeySet -from google.cloud.spanner_v1 import BurstyPool -from google.cloud.spanner_v1 import COMMIT_TIMESTAMP +from google.cloud.spanner_v1.instance import Backup +from google.cloud.spanner_v1.instance import Instance from test_utils.retry import RetryErrors from test_utils.retry import RetryInstanceState @@ -115,14 +117,19 @@ def setUpModule(): # Delete test instances that are older than an hour. cutoff = int(time.time()) - 1 * 60 * 60 - for instance in Config.CLIENT.list_instances("labels.python-spanner-systests:true"): + instance_pbs = Config.CLIENT.list_instances( + "labels.python-spanner-systests:true" + ) + for instance_pb in instance_pbs: + instance = Instance.from_pb(instance_pb, Config.CLIENT) if "created" not in instance.labels: continue create_time = int(instance.labels["created"]) if create_time > cutoff: continue # Instance cannot be deleted while backups exist. - for backup in instance.list_backups(): + for backup_pb in instance.list_backups(): + backup = Backup.from_pb(backup_pb, instance) backup.delete() instance.delete() From e18791280ee8bec6dd045bcd94c1ba245f21e2bb Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Mon, 21 Dec 2020 17:31:51 -0800 Subject: [PATCH 2/8] Blacken --- tests/system/test_system.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index ca94e83ff1..58e3668e22 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -117,9 +117,7 @@ def setUpModule(): # Delete test instances that are older than an hour. cutoff = int(time.time()) - 1 * 60 * 60 - instance_pbs = Config.CLIENT.list_instances( - "labels.python-spanner-systests:true" - ) + instance_pbs = Config.CLIENT.list_instances("labels.python-spanner-systests:true") for instance_pb in instance_pbs: instance = Instance.from_pb(instance_pb, Config.CLIENT) if "created" not in instance.labels: From 1c6da4b5c794a453fb6b811864c64a9349ee3fed Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Mon, 21 Dec 2020 22:30:37 -0800 Subject: [PATCH 3/8] Update DBAPI system test too --- tests/system/test_system_dbapi.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/system/test_system_dbapi.py b/tests/system/test_system_dbapi.py index e25fa78018..baeadd2c44 100644 --- a/tests/system/test_system_dbapi.py +++ b/tests/system/test_system_dbapi.py @@ -20,8 +20,10 @@ from google.api_core import exceptions -from google.cloud.spanner_v1 import Client from google.cloud.spanner_v1 import BurstyPool +from google.cloud.spanner_v1 import Client +from google.cloud.spanner_v1.instance import Backup +from google.cloud.spanner_v1.instance import Instance from google.cloud.spanner_dbapi.connection import Connection @@ -56,16 +58,18 @@ def setUpModule(): # Delete test instances that are older than an hour. cutoff = int(time.time()) - 1 * 60 * 60 - for instance in Config.CLIENT.list_instances( + for instance_pb in Config.CLIENT.list_instances( "labels.python-spanner-dbapi-systests:true" ): + instance = Instance.from_pb(instance_pb, Config.CLIENT) if "created" not in instance.labels: continue create_time = int(instance.labels["created"]) if create_time > cutoff: continue # Instance cannot be deleted while backups exist. - for backup in instance.list_backups(): + for backup_pb in instance.list_backups(): + backup = Backup.from_pb(backup_pb, instance) backup.delete() instance.delete() From 45087bc2c69f5c3a10bc71e4de2b99738adedc2c Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Mon, 21 Dec 2020 22:49:15 -0800 Subject: [PATCH 4/8] fix: Rename to fix "Mismatched region tag" check --- tests/system/test_system.py | 146 ++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 5bd42c5a9c..c6bdc2eecd 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -939,9 +939,9 @@ def test_batch_insert_then_read(self): ) def test_batch_insert_then_read_string_array_of_string(self): - TABLE = "string_plus_array_of_string" - COLUMNS = ["id", "name", "tags"] - ROWDATA = [ + table = "string_plus_array_of_string" + columns = ["id", "name", "tags"] + rowdata = [ (0, None, None), (1, "phred", ["yabba", "dabba", "do"]), (2, "bharney", []), @@ -951,12 +951,12 @@ def test_batch_insert_then_read_string_array_of_string(self): retry(self._db.reload)() with self._db.batch() as batch: - batch.delete(TABLE, self.ALL) - batch.insert(TABLE, COLUMNS, ROWDATA) + batch.delete(table, self.ALL) + batch.insert(table, columns, rowdata) with self._db.snapshot(read_timestamp=batch.committed) as snapshot: - rows = list(snapshot.read(TABLE, COLUMNS, self.ALL)) - self._check_rows_data(rows, expected=ROWDATA) + rows = list(snapshot.read(table, columns, self.ALL)) + self._check_rows_data(rows, expected=rowdata) def test_batch_insert_then_read_all_datatypes(self): retry = RetryInstanceState(_has_all_ddl) @@ -1570,14 +1570,14 @@ def _read_w_concurrent_update(self, transaction, pkey): transaction.update(COUNTERS_TABLE, COUNTERS_COLUMNS, [[pkey, value + 1]]) def test_transaction_read_w_concurrent_updates(self): - PKEY = "read_w_concurrent_updates" - self._transaction_concurrency_helper(self._read_w_concurrent_update, PKEY) + pkey = "read_w_concurrent_updates" + self._transaction_concurrency_helper(self._read_w_concurrent_update, pkey) def _query_w_concurrent_update(self, transaction, pkey): - SQL = "SELECT * FROM counters WHERE name = @name" + sql = "SELECT * FROM counters WHERE name = @name" rows = list( transaction.execute_sql( - SQL, params={"name": pkey}, param_types={"name": param_types.STRING} + sql, params={"name": pkey}, param_types={"name": param_types.STRING} ) ) self.assertEqual(len(rows), 1) @@ -1585,8 +1585,8 @@ def _query_w_concurrent_update(self, transaction, pkey): transaction.update(COUNTERS_TABLE, COUNTERS_COLUMNS, [[pkey, value + 1]]) def test_transaction_query_w_concurrent_updates(self): - PKEY = "query_w_concurrent_updates" - self._transaction_concurrency_helper(self._query_w_concurrent_update, PKEY) + pkey = "query_w_concurrent_updates" + self._transaction_concurrency_helper(self._query_w_concurrent_update, pkey) @unittest.skipIf(USE_EMULATOR, "Skipping concurrent transactions") def test_transaction_read_w_abort(self): @@ -1684,9 +1684,9 @@ def test_snapshot_read_w_various_staleness(self): from datetime import datetime from google.cloud._helpers import UTC - ROW_COUNT = 400 - committed = self._set_up_table(ROW_COUNT) - all_data_rows = list(self._row_data(ROW_COUNT)) + row_count = 400 + committed = self._set_up_table(row_count) + all_data_rows = list(self._row_data(row_count)) before_reads = datetime.utcnow().replace(tzinfo=UTC) @@ -1718,9 +1718,9 @@ def test_snapshot_read_w_various_staleness(self): self._check_row_data(rows, all_data_rows) def test_multiuse_snapshot_read_isolation_strong(self): - ROW_COUNT = 40 - self._set_up_table(ROW_COUNT) - all_data_rows = list(self._row_data(ROW_COUNT)) + row_count = 40 + self._set_up_table(row_count) + all_data_rows = list(self._row_data(row_count)) with self._db.snapshot(multi_use=True) as strong: before = list(strong.read(self.TABLE, self.COLUMNS, self.ALL)) self._check_row_data(before, all_data_rows) @@ -1732,9 +1732,9 @@ def test_multiuse_snapshot_read_isolation_strong(self): self._check_row_data(after, all_data_rows) def test_multiuse_snapshot_read_isolation_read_timestamp(self): - ROW_COUNT = 40 - committed = self._set_up_table(ROW_COUNT) - all_data_rows = list(self._row_data(ROW_COUNT)) + row_count = 40 + committed = self._set_up_table(row_count) + all_data_rows = list(self._row_data(row_count)) with self._db.snapshot(read_timestamp=committed, multi_use=True) as read_ts: @@ -1748,10 +1748,10 @@ def test_multiuse_snapshot_read_isolation_read_timestamp(self): self._check_row_data(after, all_data_rows) def test_multiuse_snapshot_read_isolation_exact_staleness(self): - ROW_COUNT = 40 + row_count = 40 - self._set_up_table(ROW_COUNT) - all_data_rows = list(self._row_data(ROW_COUNT)) + self._set_up_table(row_count) + all_data_rows = list(self._row_data(row_count)) time.sleep(1) delta = datetime.timedelta(microseconds=1000) @@ -1768,7 +1768,7 @@ def test_multiuse_snapshot_read_isolation_exact_staleness(self): self._check_row_data(after, all_data_rows) def test_read_w_index(self): - ROW_COUNT = 2000 + row_count = 2000 # Indexed reads cannot return non-indexed columns MY_COLUMNS = self.COLUMNS[0], self.COLUMNS[2] EXTRA_DDL = ["CREATE INDEX contacts_by_last_name ON contacts(last_name)"] @@ -1784,7 +1784,7 @@ def test_read_w_index(self): # We want to make sure the operation completes. operation.result(30) # raises on failure / timeout. - committed = self._set_up_table(ROW_COUNT, database=temp_db) + committed = self._set_up_table(row_count, database=temp_db) with temp_db.snapshot(read_timestamp=committed) as snapshot: rows = list( @@ -1794,36 +1794,36 @@ def test_read_w_index(self): ) expected = list( - reversed([(row[0], row[2]) for row in self._row_data(ROW_COUNT)]) + reversed([(row[0], row[2]) for row in self._row_data(row_count)]) ) self._check_rows_data(rows, expected) def test_read_w_single_key(self): # [START spanner_test_single_key_read] - ROW_COUNT = 40 - committed = self._set_up_table(ROW_COUNT) + row_count = 40 + committed = self._set_up_table(row_count) with self._db.snapshot(read_timestamp=committed) as snapshot: rows = list(snapshot.read(self.TABLE, self.COLUMNS, KeySet(keys=[(0,)]))) - all_data_rows = list(self._row_data(ROW_COUNT)) + all_data_rows = list(self._row_data(row_count)) expected = [all_data_rows[0]] self._check_row_data(rows, expected) # [END spanner_test_single_key_read] def test_empty_read(self): # [START spanner_test_empty_read] - ROW_COUNT = 40 - self._set_up_table(ROW_COUNT) + row_count = 40 + self._set_up_table(row_count) with self._db.snapshot() as snapshot: rows = list(snapshot.read(self.TABLE, self.COLUMNS, KeySet(keys=[(40,)]))) self._check_row_data(rows, []) # [END spanner_test_empty_read] def test_read_w_multiple_keys(self): - ROW_COUNT = 40 + row_count = 40 indices = [0, 5, 17] - committed = self._set_up_table(ROW_COUNT) + committed = self._set_up_table(row_count) with self._db.snapshot(read_timestamp=committed) as snapshot: rows = list( @@ -1834,58 +1834,58 @@ def test_read_w_multiple_keys(self): ) ) - all_data_rows = list(self._row_data(ROW_COUNT)) + all_data_rows = list(self._row_data(row_count)) expected = [row for row in all_data_rows if row[0] in indices] self._check_row_data(rows, expected) def test_read_w_limit(self): - ROW_COUNT = 3000 - LIMIT = 100 - committed = self._set_up_table(ROW_COUNT) + row_count = 3000 + limit = 100 + committed = self._set_up_table(row_count) with self._db.snapshot(read_timestamp=committed) as snapshot: - rows = list(snapshot.read(self.TABLE, self.COLUMNS, self.ALL, limit=LIMIT)) + rows = list(snapshot.read(self.TABLE, self.COLUMNS, self.ALL, limit=limit)) - all_data_rows = list(self._row_data(ROW_COUNT)) - expected = all_data_rows[:LIMIT] + all_data_rows = list(self._row_data(row_count)) + expected = all_data_rows[:limit] self._check_row_data(rows, expected) def test_read_w_ranges(self): - ROW_COUNT = 3000 - START = 1000 - END = 2000 - committed = self._set_up_table(ROW_COUNT) + row_count = 3000 + start = 1000 + end = 2000 + committed = self._set_up_table(row_count) with self._db.snapshot(read_timestamp=committed, multi_use=True) as snapshot: - all_data_rows = list(self._row_data(ROW_COUNT)) + all_data_rows = list(self._row_data(row_count)) - single_key = KeyRange(start_closed=[START], end_open=[START + 1]) + single_key = KeyRange(start_closed=[start], end_open=[start + 1]) keyset = KeySet(ranges=(single_key,)) rows = list(snapshot.read(self.TABLE, self.COLUMNS, keyset)) - expected = all_data_rows[START : START + 1] + expected = all_data_rows[start : start + 1] self._check_rows_data(rows, expected) - closed_closed = KeyRange(start_closed=[START], end_closed=[END]) + closed_closed = KeyRange(start_closed=[start], end_closed=[end]) keyset = KeySet(ranges=(closed_closed,)) rows = list(snapshot.read(self.TABLE, self.COLUMNS, keyset)) - expected = all_data_rows[START : END + 1] + expected = all_data_rows[start : end + 1] self._check_row_data(rows, expected) - closed_open = KeyRange(start_closed=[START], end_open=[END]) + closed_open = KeyRange(start_closed=[start], end_open=[end]) keyset = KeySet(ranges=(closed_open,)) rows = list(snapshot.read(self.TABLE, self.COLUMNS, keyset)) - expected = all_data_rows[START:END] + expected = all_data_rows[start:end] self._check_row_data(rows, expected) - open_open = KeyRange(start_open=[START], end_open=[END]) + open_open = KeyRange(start_open=[start], end_open=[end]) keyset = KeySet(ranges=(open_open,)) rows = list(snapshot.read(self.TABLE, self.COLUMNS, keyset)) - expected = all_data_rows[START + 1 : END] + expected = all_data_rows[start + 1 : end] self._check_row_data(rows, expected) - open_closed = KeyRange(start_open=[START], end_closed=[END]) + open_closed = KeyRange(start_open=[start], end_closed=[end]) keyset = KeySet(ranges=(open_closed,)) rows = list(snapshot.read(self.TABLE, self.COLUMNS, keyset)) - expected = all_data_rows[START + 1 : END + 1] + expected = all_data_rows[start + 1 : end + 1] self._check_row_data(rows, expected) def test_read_partial_range_until_end(self): @@ -2129,8 +2129,8 @@ def test_partition_read_w_index(self): batch_txn.close() def test_execute_sql_w_manual_consume(self): - ROW_COUNT = 3000 - committed = self._set_up_table(ROW_COUNT) + row_count = 3000 + committed = self._set_up_table(row_count) with self._db.snapshot(read_timestamp=committed) as snapshot: streamed = snapshot.execute_sql(self.SQL) @@ -2154,9 +2154,9 @@ def _check_sql_results( self._check_rows_data(rows, expected=expected) def test_multiuse_snapshot_execute_sql_isolation_strong(self): - ROW_COUNT = 40 - self._set_up_table(ROW_COUNT) - all_data_rows = list(self._row_data(ROW_COUNT)) + row_count = 40 + self._set_up_table(row_count) + all_data_rows = list(self._row_data(row_count)) with self._db.snapshot(multi_use=True) as strong: before = list(strong.execute_sql(self.SQL)) @@ -2169,7 +2169,7 @@ def test_multiuse_snapshot_execute_sql_isolation_strong(self): self._check_row_data(after, all_data_rows) def test_execute_sql_returning_array_of_struct(self): - SQL = ( + sql = ( "SELECT ARRAY(SELECT AS STRUCT C1, C2 " "FROM (SELECT 'a' AS C1, 1 AS C2 " "UNION ALL SELECT 'b' AS C1, 2 AS C2) " @@ -2177,14 +2177,14 @@ def test_execute_sql_returning_array_of_struct(self): ) self._check_sql_results( self._db, - sql=SQL, + sql=sql, params=None, param_types=None, expected=[[[["a", 1], ["b", 2]]]], ) def test_execute_sql_returning_empty_array_of_struct(self): - SQL = ( + sql = ( "SELECT ARRAY(SELECT AS STRUCT C1, C2 " "FROM (SELECT 2 AS C1) X " "JOIN (SELECT 1 AS C2) Y " @@ -2194,7 +2194,7 @@ def test_execute_sql_returning_empty_array_of_struct(self): self._db.snapshot(multi_use=True) self._check_sql_results( - self._db, sql=SQL, params=None, param_types=None, expected=[[[]]] + self._db, sql=sql, params=None, param_types=None, expected=[[[]]] ) def test_invalid_type(self): @@ -2359,11 +2359,11 @@ def test_execute_sql_w_numeric_bindings(self): self._bind_test_helper(TypeCode.NUMERIC, NUMERIC_1, [NUMERIC_1, NUMERIC_2]) def test_execute_sql_w_query_param_struct(self): - NAME = "Phred" - COUNT = 123 - SIZE = 23.456 - HEIGHT = 188.0 - WEIGHT = 97.6 + name = "Phred" + count = 123 + size = 23.456 + height = 188.0 + weight = 97.6 record_type = param_types.Struct( [ @@ -2416,9 +2416,9 @@ def test_execute_sql_w_query_param_struct(self): self._check_sql_results( self._db, sql="SELECT @r.name, @r.count, @r.size, @r.nested.weight", - params={"r": (NAME, COUNT, SIZE, (HEIGHT, WEIGHT))}, + params={"r": (name, count, size, (height, weight))}, param_types={"r": record_type}, - expected=[(NAME, COUNT, SIZE, WEIGHT)], + expected=[(name, count, size, weight)], order=False, ) From c0923e15750aade8d45d7827501cb33308bd7050 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 22 Dec 2020 11:05:50 -0800 Subject: [PATCH 5/8] CI check: log span test errors --- tests/system/test_system.py | 316 ++++++++++++++++++++++-------------- 1 file changed, 196 insertions(+), 120 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 58e3668e22..accac9be29 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -12,13 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +from pprint import pformat import collections import datetime import decimal +import logging import math import operator import os import struct +import sys import threading import time import unittest @@ -52,6 +55,11 @@ from tests._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED +logger = logging.getLogger(__name__) +logger.addHandler(logging.StreamHandler(sys.stderr)) +logger.setLevel(logging.INFO) + + CREATE_INSTANCE = os.getenv("GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE") is not None USE_EMULATOR = os.getenv("SPANNER_EMULATOR_HOST") is not None SKIP_BACKUP_TESTS = os.getenv("SKIP_BACKUP_TESTS") is not None @@ -905,43 +913,63 @@ def test_batch_insert_then_read(self): if HAS_OPENTELEMETRY_INSTALLED: span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 4) - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[0], - ) - self.assertSpanAttributes( - "CloudSpanner.Commit", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "num_mutations": 2} - ), - span=span_list[1], - ) - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[2], - ) - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "columns": self.COLUMNS, - "table_id": self.TABLE, - } - ), - span=span_list[3], - ) + try: + self.assertEqual(len(span_list), 4) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[0], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.Commit", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "num_mutations": 2} + ), + span=span_list[1], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[2], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "columns": self.COLUMNS, + "table_id": self.TABLE, + } + ), + span=span_list[3], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise def test_batch_insert_then_read_string_array_of_string(self): TABLE = "string_plus_array_of_string" @@ -1049,74 +1077,110 @@ def test_transaction_read_and_insert_then_rollback(self): if HAS_OPENTELEMETRY_INSTALLED: span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 8) - self.assertSpanAttributes( - "CloudSpanner.CreateSession", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[0], - ) - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[1], - ) - self.assertSpanAttributes( - "CloudSpanner.Commit", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "num_mutations": 1} - ), - span=span_list[2], - ) - self.assertSpanAttributes( - "CloudSpanner.BeginTransaction", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[3], - ) - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[4], - ) - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[5], - ) - self.assertSpanAttributes( - "CloudSpanner.Rollback", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[6], - ) - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[7], - ) + try: + self.assertEqual(len(span_list), 8) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.CreateSession", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[0], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[1], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.Commit", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "num_mutations": 1} + ), + span=span_list[2], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.BeginTransaction", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[3], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[4], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[5], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.Rollback", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[6], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[7], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise def _transaction_read_then_raise(self, transaction): rows = list(transaction.read(self.TABLE, self.COLUMNS, self.ALL)) @@ -1464,21 +1528,33 @@ def unit_of_work(transaction, self): session.run_in_transaction(unit_of_work, self) span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 6) - self.assertEqual( - list(map(lambda span: span.name, span_list)), - [ - "CloudSpanner.CreateSession", - "CloudSpanner.Commit", - "CloudSpanner.BeginTransaction", - "CloudSpanner.DMLTransaction", - "CloudSpanner.Commit", - "Test Span", - ], - ) - for span in span_list[2:-1]: - self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) - self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) + try: + self.assertEqual(len(span_list), 6) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + self.assertEqual( + list(map(lambda span: span.name, span_list)), + [ + "CloudSpanner.CreateSession", + "CloudSpanner.Commit", + "CloudSpanner.BeginTransaction", + "CloudSpanner.DMLTransaction", + "CloudSpanner.Commit", + "Test Span", + ], + ) + except AssertionError: + logger.error(pformat(span_list)) + raise + try: + for span in span_list[2:-1]: + self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) + self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) + except AssertionError: + logger.error(pformat(span_list)) + raise def test_execute_partitioned_dml(self): # [START spanner_test_dml_partioned_dml_update] From 4e135def973ac016437ca621e0435ce0f002f5b7 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 22 Dec 2020 11:06:45 -0800 Subject: [PATCH 6/8] CI check: don't raise --- tests/system/test_system.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index accac9be29..717fdb3d05 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -917,7 +917,6 @@ def test_batch_insert_then_read(self): self.assertEqual(len(span_list), 4) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -929,7 +928,6 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.Commit", @@ -941,7 +939,6 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -953,7 +950,6 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -969,7 +965,6 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) - raise def test_batch_insert_then_read_string_array_of_string(self): TABLE = "string_plus_array_of_string" @@ -1081,7 +1076,6 @@ def test_transaction_read_and_insert_then_rollback(self): self.assertEqual(len(span_list), 8) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.CreateSession", @@ -1090,7 +1084,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -1102,7 +1095,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.Commit", @@ -1114,7 +1106,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.BeginTransaction", @@ -1123,7 +1114,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1139,7 +1129,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1155,7 +1144,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.Rollback", @@ -1164,7 +1152,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1180,7 +1167,6 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) - raise def _transaction_read_then_raise(self, transaction): rows = list(transaction.read(self.TABLE, self.COLUMNS, self.ALL)) @@ -1532,7 +1518,6 @@ def unit_of_work(transaction, self): self.assertEqual(len(span_list), 6) except AssertionError: logger.error(pformat(span_list)) - raise try: self.assertEqual( list(map(lambda span: span.name, span_list)), @@ -1547,14 +1532,12 @@ def unit_of_work(transaction, self): ) except AssertionError: logger.error(pformat(span_list)) - raise try: for span in span_list[2:-1]: self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) except AssertionError: logger.error(pformat(span_list)) - raise def test_execute_partitioned_dml(self): # [START spanner_test_dml_partioned_dml_update] From ea3d736799723be34c0ceae6cc62bbb5c001ad39 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 22 Dec 2020 12:06:02 -0800 Subject: [PATCH 7/8] Revert "CI check: don't raise" This reverts commit 4e135def973ac016437ca621e0435ce0f002f5b7. --- tests/system/test_system.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 717fdb3d05..accac9be29 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -917,6 +917,7 @@ def test_batch_insert_then_read(self): self.assertEqual(len(span_list), 4) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -928,6 +929,7 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.Commit", @@ -939,6 +941,7 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -950,6 +953,7 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -965,6 +969,7 @@ def test_batch_insert_then_read(self): ) except AssertionError: logger.error(pformat(span_list)) + raise def test_batch_insert_then_read_string_array_of_string(self): TABLE = "string_plus_array_of_string" @@ -1076,6 +1081,7 @@ def test_transaction_read_and_insert_then_rollback(self): self.assertEqual(len(span_list), 8) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.CreateSession", @@ -1084,6 +1090,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.GetSession", @@ -1095,6 +1102,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.Commit", @@ -1106,6 +1114,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.BeginTransaction", @@ -1114,6 +1123,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1129,6 +1139,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1144,6 +1155,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.Rollback", @@ -1152,6 +1164,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertSpanAttributes( "CloudSpanner.ReadOnlyTransaction", @@ -1167,6 +1180,7 @@ def test_transaction_read_and_insert_then_rollback(self): ) except AssertionError: logger.error(pformat(span_list)) + raise def _transaction_read_then_raise(self, transaction): rows = list(transaction.read(self.TABLE, self.COLUMNS, self.ALL)) @@ -1518,6 +1532,7 @@ def unit_of_work(transaction, self): self.assertEqual(len(span_list), 6) except AssertionError: logger.error(pformat(span_list)) + raise try: self.assertEqual( list(map(lambda span: span.name, span_list)), @@ -1532,12 +1547,14 @@ def unit_of_work(transaction, self): ) except AssertionError: logger.error(pformat(span_list)) + raise try: for span in span_list[2:-1]: self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) except AssertionError: logger.error(pformat(span_list)) + raise def test_execute_partitioned_dml(self): # [START spanner_test_dml_partioned_dml_update] From ea43ca1c9c4b05f9e8fb89b85077844e9994d81a Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 22 Dec 2020 12:06:43 -0800 Subject: [PATCH 8/8] Revert "CI check: log span test errors" This reverts commit c0923e15750aade8d45d7827501cb33308bd7050. --- tests/system/test_system.py | 316 ++++++++++++++---------------------- 1 file changed, 120 insertions(+), 196 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index accac9be29..58e3668e22 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -12,16 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pprint import pformat import collections import datetime import decimal -import logging import math import operator import os import struct -import sys import threading import time import unittest @@ -55,11 +52,6 @@ from tests._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED -logger = logging.getLogger(__name__) -logger.addHandler(logging.StreamHandler(sys.stderr)) -logger.setLevel(logging.INFO) - - CREATE_INSTANCE = os.getenv("GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE") is not None USE_EMULATOR = os.getenv("SPANNER_EMULATOR_HOST") is not None SKIP_BACKUP_TESTS = os.getenv("SKIP_BACKUP_TESTS") is not None @@ -913,63 +905,43 @@ def test_batch_insert_then_read(self): if HAS_OPENTELEMETRY_INSTALLED: span_list = self.memory_exporter.get_finished_spans() - try: - self.assertEqual(len(span_list), 4) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[0], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.Commit", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "num_mutations": 2} - ), - span=span_list[1], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[2], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "columns": self.COLUMNS, - "table_id": self.TABLE, - } - ), - span=span_list[3], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise + self.assertEqual(len(span_list), 4) + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[0], + ) + self.assertSpanAttributes( + "CloudSpanner.Commit", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "num_mutations": 2} + ), + span=span_list[1], + ) + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[2], + ) + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "columns": self.COLUMNS, + "table_id": self.TABLE, + } + ), + span=span_list[3], + ) def test_batch_insert_then_read_string_array_of_string(self): TABLE = "string_plus_array_of_string" @@ -1077,110 +1049,74 @@ def test_transaction_read_and_insert_then_rollback(self): if HAS_OPENTELEMETRY_INSTALLED: span_list = self.memory_exporter.get_finished_spans() - try: - self.assertEqual(len(span_list), 8) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.CreateSession", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[0], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.GetSession", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "session_found": True} - ), - span=span_list[1], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.Commit", - attributes=dict( - BASE_ATTRIBUTES, - **{"db.instance": self._db.name, "num_mutations": 1} - ), - span=span_list[2], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.BeginTransaction", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[3], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[4], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[5], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.Rollback", - attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), - span=span_list[6], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertSpanAttributes( - "CloudSpanner.ReadOnlyTransaction", - attributes=dict( - BASE_ATTRIBUTES, - **{ - "db.instance": self._db.name, - "table_id": self.TABLE, - "columns": self.COLUMNS, - } - ), - span=span_list[7], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise + self.assertEqual(len(span_list), 8) + self.assertSpanAttributes( + "CloudSpanner.CreateSession", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[0], + ) + self.assertSpanAttributes( + "CloudSpanner.GetSession", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "session_found": True} + ), + span=span_list[1], + ) + self.assertSpanAttributes( + "CloudSpanner.Commit", + attributes=dict( + BASE_ATTRIBUTES, + **{"db.instance": self._db.name, "num_mutations": 1} + ), + span=span_list[2], + ) + self.assertSpanAttributes( + "CloudSpanner.BeginTransaction", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[3], + ) + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[4], + ) + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[5], + ) + self.assertSpanAttributes( + "CloudSpanner.Rollback", + attributes=dict(BASE_ATTRIBUTES, **{"db.instance": self._db.name}), + span=span_list[6], + ) + self.assertSpanAttributes( + "CloudSpanner.ReadOnlyTransaction", + attributes=dict( + BASE_ATTRIBUTES, + **{ + "db.instance": self._db.name, + "table_id": self.TABLE, + "columns": self.COLUMNS, + } + ), + span=span_list[7], + ) def _transaction_read_then_raise(self, transaction): rows = list(transaction.read(self.TABLE, self.COLUMNS, self.ALL)) @@ -1528,33 +1464,21 @@ def unit_of_work(transaction, self): session.run_in_transaction(unit_of_work, self) span_list = self.memory_exporter.get_finished_spans() - try: - self.assertEqual(len(span_list), 6) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - self.assertEqual( - list(map(lambda span: span.name, span_list)), - [ - "CloudSpanner.CreateSession", - "CloudSpanner.Commit", - "CloudSpanner.BeginTransaction", - "CloudSpanner.DMLTransaction", - "CloudSpanner.Commit", - "Test Span", - ], - ) - except AssertionError: - logger.error(pformat(span_list)) - raise - try: - for span in span_list[2:-1]: - self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) - self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) - except AssertionError: - logger.error(pformat(span_list)) - raise + self.assertEqual(len(span_list), 6) + self.assertEqual( + list(map(lambda span: span.name, span_list)), + [ + "CloudSpanner.CreateSession", + "CloudSpanner.Commit", + "CloudSpanner.BeginTransaction", + "CloudSpanner.DMLTransaction", + "CloudSpanner.Commit", + "Test Span", + ], + ) + for span in span_list[2:-1]: + self.assertEqual(span.context.trace_id, span_list[-1].context.trace_id) + self.assertEqual(span.parent.span_id, span_list[-1].context.span_id) def test_execute_partitioned_dml(self): # [START spanner_test_dml_partioned_dml_update]