Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd14b13

Browse files
authored
test: fix PITR restored database version time assertion (googleapis#238)
This PR fixes the assertion to use `metadata.backup_info.version_time` instead of `metadata.backup_info.create_time`. It looks it was passing before the backend correctly supported it and I forgot to re-run the tests before merging googleapis#148 (whoops!) and so it is currently failing and preventing googleapis#205 from being merged: https://source.cloud.google.com/results/invocations/8f0f5dab-1b35-4ce3-bb72-0ce9e79ab89d/targets/cloud-devrel%2Fclient-libraries%2Fpython%2Fgoogleapis%2Fpython-spanner%2Fpresubmit%2Fpresubmit/log
1 parent a082e5d commit fd14b13

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

test.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import base64
2+
import time
3+
from google.cloud import spanner
4+
from google.auth.credentials import AnonymousCredentials
5+
6+
instance_id = 'test-instance'
7+
database_id = 'test-db'
8+
9+
spanner_client = spanner.Client(
10+
project='test-project',
11+
client_options={"api_endpoint": 'localhost:9010'},
12+
credentials=AnonymousCredentials()
13+
)
14+
15+
instance = spanner_client.instance(instance_id)
16+
op = instance.create()
17+
op.result()
18+
19+
database = instance.database(database_id, ddl_statements=[
20+
"CREATE TABLE Test (id STRING(36) NOT NULL, megafield BYTES(MAX)) PRIMARY KEY (id)"
21+
])
22+
op = database.create()
23+
op.result()
24+
25+
# This must be large enough that the SDK will split the megafield payload across two query chunks
26+
# and try to recombine them, causing the error:
27+
data = base64.standard_b64encode(("a" * 1000000).encode("utf8"))
28+
29+
try:
30+
with database.batch() as batch:
31+
batch.insert(
32+
table="Test",
33+
columns=("id", "megafield"),
34+
values=[
35+
(1, data),
36+
],
37+
)
38+
39+
with database.snapshot() as snapshot:
40+
toc = time.time()
41+
results = snapshot.execute_sql(
42+
"SELECT * FROM Test"
43+
)
44+
tic = time.time()
45+
46+
print("TIME: ", tic - toc)
47+
48+
for row in results:
49+
print("Id: ", row[0])
50+
print("Megafield: ", row[1][:100])
51+
finally:
52+
database.drop()
53+
instance.delete()

tests/system/test_system.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,12 @@ def test_backup_workflow(self):
725725
operation = database.restore(source=backup)
726726
restored_db = operation.result()
727727
self.assertEqual(
728-
self.database_version_time, restored_db.restore_info.backup_info.create_time
728+
self.database_version_time,
729+
restored_db.restore_info.backup_info.version_time,
729730
)
730731

731732
metadata = operation.metadata
732-
self.assertEqual(self.database_version_time, metadata.backup_info.create_time)
733+
self.assertEqual(self.database_version_time, metadata.backup_info.version_time)
733734

734735
database.drop()
735736
backup.delete()

0 commit comments

Comments
 (0)