5555CREATE_INSTANCE = os .getenv ("GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE" ) is not None
5656USE_EMULATOR = os .getenv ("SPANNER_EMULATOR_HOST" ) is not None
5757SKIP_BACKUP_TESTS = os .getenv ("SKIP_BACKUP_TESTS" ) is not None
58+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS = int (
59+ os .getenv ("SPANNER_OPERATION_TIMEOUT_IN_SECONDS" , 60 )
60+ )
5861
5962if CREATE_INSTANCE :
6063 INSTANCE_ID = "google-cloud" + unique_resource_id ("-" )
@@ -149,7 +152,9 @@ def setUpModule():
149152 INSTANCE_ID , config_name , labels = labels
150153 )
151154 created_op = Config .INSTANCE .create ()
152- created_op .result (30 ) # block until completion
155+ created_op .result (
156+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
157+ ) # block until completion
153158
154159 else :
155160 Config .INSTANCE = Config .CLIENT .instance (INSTANCE_ID )
@@ -208,7 +213,9 @@ def test_create_instance(self):
208213 self .instances_to_delete .append (instance )
209214
210215 # We want to make sure the operation completes.
211- operation .result (30 ) # raises on failure / timeout.
216+ operation .result (
217+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
218+ ) # raises on failure / timeout.
212219
213220 # Create a new instance instance and make sure it is the same.
214221 instance_alt = Config .CLIENT .instance (
@@ -227,7 +234,9 @@ def test_update_instance(self):
227234 operation = Config .INSTANCE .update ()
228235
229236 # We want to make sure the operation completes.
230- operation .result (30 ) # raises on failure / timeout.
237+ operation .result (
238+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
239+ ) # raises on failure / timeout.
231240
232241 # Create a new instance instance and reload it.
233242 instance_alt = Config .CLIENT .instance (INSTANCE_ID , None )
@@ -308,7 +317,9 @@ def setUpClass(cls):
308317 cls .DATABASE_NAME , ddl_statements = ddl_statements , pool = pool
309318 )
310319 operation = cls ._db .create ()
311- operation .result (30 ) # raises on failure / timeout.
320+ operation .result (
321+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
322+ ) # raises on failure / timeout.
312323
313324 @classmethod
314325 def tearDownClass (cls ):
@@ -337,7 +348,9 @@ def test_create_database(self):
337348 self .to_delete .append (temp_db )
338349
339350 # We want to make sure the operation completes.
340- operation .result (30 ) # raises on failure / timeout.
351+ operation .result (
352+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
353+ ) # raises on failure / timeout.
341354
342355 database_ids = [database .name for database in Config .INSTANCE .list_databases ()]
343356 self .assertIn (temp_db .name , database_ids )
@@ -483,8 +496,8 @@ def setUpClass(cls):
483496 cls ._dbs = [db1 , db2 ]
484497 op1 = db1 .create ()
485498 op2 = db2 .create ()
486- op1 .result (30 ) # raises on failure / timeout.
487- op2 .result (30 ) # raises on failure / timeout.
499+ op1 .result (SPANNER_OPERATION_TIMEOUT_IN_SECONDS ) # raises on failure / timeout.
500+ op2 .result (SPANNER_OPERATION_TIMEOUT_IN_SECONDS ) # raises on failure / timeout.
488501
489502 current_config = Config .INSTANCE .configuration_name
490503 same_config_instance_id = "same-config" + unique_resource_id ("-" )
@@ -494,7 +507,7 @@ def setUpClass(cls):
494507 same_config_instance_id , current_config , labels = labels
495508 )
496509 op = cls ._same_config_instance .create ()
497- op .result (30 )
510+ op .result (SPANNER_OPERATION_TIMEOUT_IN_SECONDS )
498511 cls ._instances = [cls ._same_config_instance ]
499512
500513 retry = RetryErrors (exceptions .ServiceUnavailable )
@@ -513,7 +526,7 @@ def setUpClass(cls):
513526 diff_config_instance_id , diff_configs [0 ], labels = labels
514527 )
515528 op = cls ._diff_config_instance .create ()
516- op .result (30 )
529+ op .result (SPANNER_OPERATION_TIMEOUT_IN_SECONDS )
517530 cls ._instances .append (cls ._diff_config_instance )
518531
519532 @classmethod
@@ -675,7 +688,7 @@ def test_multi_create_cancel_update_error_restore_errors(self):
675688 return
676689 new_db = self ._diff_config_instance .database ("diff_config" )
677690 op = new_db .create ()
678- op .result (30 )
691+ op .result (SPANNER_OPERATION_TIMEOUT_IN_SECONDS )
679692 self .to_drop .append (new_db )
680693 with self .assertRaises (exceptions .InvalidArgument ):
681694 new_db .restore (source = backup1 )
@@ -866,7 +879,9 @@ def setUpClass(cls):
866879 cls .DATABASE_NAME , ddl_statements = ddl_statements , pool = pool
867880 )
868881 operation = cls ._db .create ()
869- operation .result (30 ) # raises on failure / timeout.
882+ operation .result (
883+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
884+ ) # raises on failure / timeout.
870885
871886 @classmethod
872887 def tearDownClass (cls ):
@@ -1788,7 +1803,9 @@ def test_read_w_index(self):
17881803 self .to_delete .append (_DatabaseDropper (temp_db ))
17891804
17901805 # We want to make sure the operation completes.
1791- operation .result (30 ) # raises on failure / timeout.
1806+ operation .result (
1807+ SPANNER_OPERATION_TIMEOUT_IN_SECONDS
1808+ ) # raises on failure / timeout.
17921809 committed = self ._set_up_table (row_count , database = temp_db )
17931810
17941811 with temp_db .snapshot (read_timestamp = committed ) as snapshot :
0 commit comments