|
20 | 20 | from google.api_core import exceptions
|
21 | 21 | from google.iam.v1 import policy_pb2
|
22 | 22 | from google.cloud import spanner_v1
|
| 23 | +from google.cloud.spanner_v1.pool import FixedSizePool, PingingPool |
23 | 24 | from google.type import expr_pb2
|
24 | 25 | from . import _helpers
|
25 | 26 | from . import _sample_data
|
@@ -73,6 +74,61 @@ def test_create_database(shared_instance, databases_to_delete, database_dialect)
|
73 | 74 | assert temp_db.name in database_ids
|
74 | 75 |
|
75 | 76 |
|
| 77 | +def test_database_binding_of_fixed_size_pool( |
| 78 | + not_emulator, shared_instance, databases_to_delete, not_postgres |
| 79 | +): |
| 80 | + temp_db_id = _helpers.unique_id("fixed_size_db", separator="_") |
| 81 | + temp_db = shared_instance.database(temp_db_id) |
| 82 | + |
| 83 | + create_op = temp_db.create() |
| 84 | + databases_to_delete.append(temp_db) |
| 85 | + create_op.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout. |
| 86 | + |
| 87 | + # Create role and grant select permission on table contacts for parent role. |
| 88 | + ddl_statements = _helpers.DDL_STATEMENTS + [ |
| 89 | + "CREATE ROLE parent", |
| 90 | + "GRANT SELECT ON TABLE contacts TO ROLE parent", |
| 91 | + ] |
| 92 | + operation = temp_db.update_ddl(ddl_statements) |
| 93 | + operation.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout. |
| 94 | + |
| 95 | + pool = FixedSizePool( |
| 96 | + size=1, |
| 97 | + default_timeout=500, |
| 98 | + database_role="parent", |
| 99 | + ) |
| 100 | + database = shared_instance.database(temp_db.name, pool=pool) |
| 101 | + assert database._pool.database_role == "parent" |
| 102 | + |
| 103 | + |
| 104 | +def test_database_binding_of_pinging_pool( |
| 105 | + not_emulator, shared_instance, databases_to_delete, not_postgres |
| 106 | +): |
| 107 | + temp_db_id = _helpers.unique_id("binding_db", separator="_") |
| 108 | + temp_db = shared_instance.database(temp_db_id) |
| 109 | + |
| 110 | + create_op = temp_db.create() |
| 111 | + databases_to_delete.append(temp_db) |
| 112 | + create_op.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout. |
| 113 | + |
| 114 | + # Create role and grant select permission on table contacts for parent role. |
| 115 | + ddl_statements = _helpers.DDL_STATEMENTS + [ |
| 116 | + "CREATE ROLE parent", |
| 117 | + "GRANT SELECT ON TABLE contacts TO ROLE parent", |
| 118 | + ] |
| 119 | + operation = temp_db.update_ddl(ddl_statements) |
| 120 | + operation.result(DBAPI_OPERATION_TIMEOUT) # raises on failure / timeout. |
| 121 | + |
| 122 | + pool = PingingPool( |
| 123 | + size=1, |
| 124 | + default_timeout=500, |
| 125 | + ping_interval=100, |
| 126 | + database_role="parent", |
| 127 | + ) |
| 128 | + database = shared_instance.database(temp_db.name, pool=pool) |
| 129 | + assert database._pool.database_role == "parent" |
| 130 | + |
| 131 | + |
76 | 132 | def test_create_database_pitr_invalid_retention_period(
|
77 | 133 | not_emulator, # PITR-lite features are not supported by the emulator
|
78 | 134 | not_postgres,
|
|
0 commit comments