Skip to content

Commit dab92dd

Browse files
committed
Remove duplicate code
1 parent e67cc9e commit dab92dd

File tree

2 files changed

+25
-46
lines changed

2 files changed

+25
-46
lines changed

tests/mockserver_tests/mock_server_test_base.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
start_mock_server,
2121
SpannerServicer,
2222
)
23-
from google.cloud.spanner_v1.client import Client
2423
import google.cloud.spanner_v1.types.type as spanner_type
2524
import google.cloud.spanner_v1.types.result_set as result_set
2625
from google.api_core.client_options import ClientOptions
@@ -79,27 +78,6 @@ def unavailable_status() -> _Status:
7978
return status
8079

8180

82-
# Creates an UNAVAILABLE status with the smallest possible retry delay.
83-
def unavailable_status() -> _Status:
84-
error = status_pb2.Status(
85-
code=code_pb2.UNAVAILABLE,
86-
message="Service unavailable.",
87-
)
88-
retry_info = RetryInfo(retry_delay=Duration(seconds=0, nanos=1))
89-
status = _Status(
90-
code=code_to_grpc_status_code(error.code),
91-
details=error.message,
92-
trailing_metadata=(
93-
("grpc-status-details-bin", error.SerializeToString()),
94-
(
95-
"google.rpc.retryinfo-bin",
96-
retry_info.SerializeToString(),
97-
),
98-
),
99-
)
100-
return status
101-
102-
10381
def add_error(method: str, error: status_pb2.Status):
10482
MockServerTestBase.spanner_service.mock_spanner.add_error(method, error)
10583

@@ -213,5 +191,4 @@ def database(self) -> Database:
213191
pool=FixedSizePool(size=10),
214192
enable_interceptors_in_tests=True,
215193
)
216-
print("self._database", self._database)
217194
return self._database

tests/unit/test_spanner.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
from google.cloud.spanner_v1.keyset import KeySet
3939

4040
from google.cloud.spanner_v1._helpers import (
41-
AtomicCounter,
4241
_make_value_pb,
4342
_merge_query_options,
43+
)
44+
from google.cloud.spanner_v1._helpers import (
45+
AtomicCounter,
4446
_metadata_with_request_id,
4547
)
4648
from google.cloud.spanner_v1.request_id_header import REQ_RAND_PROCESS_ID
@@ -545,7 +547,7 @@ def test_transaction_should_include_begin_with_first_query(self):
545547
("x-goog-spanner-route-to-leader", "true"),
546548
(
547549
"x-goog-spanner-request-id",
548-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
550+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
549551
),
550552
],
551553
timeout=TIMEOUT,
@@ -566,7 +568,7 @@ def test_transaction_should_include_begin_with_first_read(self):
566568
("x-goog-spanner-route-to-leader", "true"),
567569
(
568570
"x-goog-spanner-request-id",
569-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
571+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
570572
),
571573
],
572574
retry=RETRY,
@@ -586,7 +588,7 @@ def test_transaction_should_include_begin_with_first_batch_update(self):
586588
("x-goog-spanner-route-to-leader", "true"),
587589
(
588590
"x-goog-spanner-request-id",
589-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
591+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
590592
),
591593
],
592594
retry=RETRY,
@@ -615,7 +617,7 @@ def test_transaction_should_include_begin_w_exclude_txn_from_change_streams_with
615617
("x-goog-spanner-route-to-leader", "true"),
616618
(
617619
"x-goog-spanner-request-id",
618-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
620+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
619621
),
620622
],
621623
)
@@ -645,7 +647,7 @@ def test_transaction_should_include_begin_w_isolation_level_with_first_update(
645647
("x-goog-spanner-route-to-leader", "true"),
646648
(
647649
"x-goog-spanner-request-id",
648-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
650+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
649651
),
650652
],
651653
)
@@ -667,7 +669,7 @@ def test_transaction_should_use_transaction_id_if_error_with_first_batch_update(
667669
("x-goog-spanner-route-to-leader", "true"),
668670
(
669671
"x-goog-spanner-request-id",
670-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
672+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
671673
),
672674
],
673675
retry=RETRY,
@@ -685,7 +687,7 @@ def test_transaction_should_use_transaction_id_if_error_with_first_batch_update(
685687
("x-goog-spanner-route-to-leader", "true"),
686688
(
687689
"x-goog-spanner-request-id",
688-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
690+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
689691
),
690692
],
691693
)
@@ -705,7 +707,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_query(self):
705707
("x-goog-spanner-route-to-leader", "true"),
706708
(
707709
"x-goog-spanner-request-id",
708-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
710+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
709711
),
710712
],
711713
)
@@ -722,7 +724,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_query(self):
722724
("x-goog-spanner-route-to-leader", "true"),
723725
(
724726
"x-goog-spanner-request-id",
725-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
727+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
726728
),
727729
],
728730
)
@@ -742,7 +744,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_update(self):
742744
("x-goog-spanner-route-to-leader", "true"),
743745
(
744746
"x-goog-spanner-request-id",
745-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
747+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
746748
),
747749
],
748750
)
@@ -759,7 +761,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_update(self):
759761
("x-goog-spanner-route-to-leader", "true"),
760762
(
761763
"x-goog-spanner-request-id",
762-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
764+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
763765
),
764766
],
765767
)
@@ -784,7 +786,7 @@ def test_transaction_execute_sql_w_directed_read_options(self):
784786
("x-goog-spanner-route-to-leader", "true"),
785787
(
786788
"x-goog-spanner-request-id",
787-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
789+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
788790
),
789791
],
790792
retry=gapic_v1.method.DEFAULT,
@@ -811,7 +813,7 @@ def test_transaction_streaming_read_w_directed_read_options(self):
811813
("x-goog-spanner-route-to-leader", "true"),
812814
(
813815
"x-goog-spanner-request-id",
814-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
816+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
815817
),
816818
],
817819
retry=RETRY,
@@ -831,7 +833,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_read(self):
831833
("x-goog-spanner-route-to-leader", "true"),
832834
(
833835
"x-goog-spanner-request-id",
834-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
836+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
835837
),
836838
],
837839
retry=RETRY,
@@ -846,7 +848,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_read(self):
846848
("x-goog-spanner-route-to-leader", "true"),
847849
(
848850
"x-goog-spanner-request-id",
849-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
851+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
850852
),
851853
],
852854
retry=RETRY,
@@ -866,7 +868,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_batch_update(se
866868
("x-goog-spanner-route-to-leader", "true"),
867869
(
868870
"x-goog-spanner-request-id",
869-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
871+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
870872
),
871873
],
872874
retry=RETRY,
@@ -882,7 +884,7 @@ def test_transaction_should_use_transaction_id_returned_by_first_batch_update(se
882884
("x-goog-spanner-route-to-leader", "true"),
883885
(
884886
"x-goog-spanner-request-id",
885-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
887+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
886888
),
887889
],
888890
retry=RETRY,
@@ -926,7 +928,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
926928
("x-goog-spanner-route-to-leader", "true"),
927929
(
928930
"x-goog-spanner-request-id",
929-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
931+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
930932
),
931933
],
932934
)
@@ -940,7 +942,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
940942
("x-goog-spanner-route-to-leader", "true"),
941943
(
942944
"x-goog-spanner-request-id",
943-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.1",
945+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.2.1",
944946
),
945947
],
946948
)
@@ -952,7 +954,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
952954
("x-goog-spanner-route-to-leader", "true"),
953955
(
954956
"x-goog-spanner-request-id",
955-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.3.1",
957+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.3.1",
956958
),
957959
],
958960
retry=RETRY,
@@ -1000,7 +1002,7 @@ def test_transaction_for_concurrent_statement_should_begin_one_transaction_with_
10001002
("x-goog-spanner-route-to-leader", "true"),
10011003
(
10021004
"x-goog-spanner-request-id",
1003-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.3.1",
1005+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.3.1",
10041006
),
10051007
],
10061008
)
@@ -1216,7 +1218,7 @@ def test_transaction_should_execute_sql_with_route_to_leader_disabled(self):
12161218
("google-cloud-resource-prefix", database.name),
12171219
(
12181220
"x-goog-spanner-request-id",
1219-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.1",
1221+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.1.1.1",
12201222
),
12211223
],
12221224
timeout=TIMEOUT,

0 commit comments

Comments
 (0)