diff --git a/packages/google-cloud-bigtable/samples/data_client/hello/main.py b/packages/google-cloud-bigtable/samples/data_client/hello/main.py index b317b35ec336..89a14904f99d 100644 --- a/packages/google-cloud-bigtable/samples/data_client/hello/main.py +++ b/packages/google-cloud-bigtable/samples/data_client/hello/main.py @@ -72,6 +72,18 @@ def main(project_id, instance_id, table_id): # [END bigtable_hw_create_table] try: + # Wait for table creation to propagate to the data plane. + from google.api_core.exceptions import FailedPrecondition, NotFound + + table.read_row( + b"greeting0", + operation_timeout=120, + retryable_errors=( + *table.default_read_rows_retryable_errors, + FailedPrecondition, + NotFound, + ), + ) # [START bigtable_hw_write_rows] print("Writing some greetings to the table.") greetings = [b"Hello World!", b"Hello Cloud Bigtable!", b"Hello Python!"] diff --git a/packages/google-cloud-bigtable/samples/data_client_async/hello/async_main.py b/packages/google-cloud-bigtable/samples/data_client_async/hello/async_main.py index 46c91a2358c9..efdd7191e311 100644 --- a/packages/google-cloud-bigtable/samples/data_client_async/hello/async_main.py +++ b/packages/google-cloud-bigtable/samples/data_client_async/hello/async_main.py @@ -72,6 +72,18 @@ async def main(project_id, instance_id, table_id): # [END bigtable_async_hw_create_table] try: + # Wait for table creation to propagate to the data plane. + from google.api_core.exceptions import FailedPrecondition, NotFound + + await table.read_row( + b"greeting0", + operation_timeout=120, + retryable_errors=( + *table.default_read_rows_retryable_errors, + FailedPrecondition, + NotFound, + ), + ) # [START bigtable_async_hw_write_rows] print("Writing some greetings to the table.") greetings = [b"Hello World!", b"Hello Cloud Bigtable!", b"Hello Python!"] diff --git a/packages/google-cloud-bigtable/tests/unit/data/_async/test_mutations_batcher.py b/packages/google-cloud-bigtable/tests/unit/data/_async/test_mutations_batcher.py index b144a1bbeb0c..22780004f82d 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_async/test_mutations_batcher.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_async/test_mutations_batcher.py @@ -405,7 +405,7 @@ async def test_ctor_defaults(self): instance._retryable_errors == table.default_mutate_rows_retryable_errors ) - await CrossSync.yield_to_event_loop() + await CrossSync.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] == 5 assert isinstance(instance._flush_timer, CrossSync.Future) @@ -457,7 +457,7 @@ async def test_ctor_explicit(self): assert instance._operation_timeout == operation_timeout assert instance._attempt_timeout == attempt_timeout assert instance._retryable_errors == retryable_errors - await CrossSync.yield_to_event_loop() + await CrossSync.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] == flush_interval assert isinstance(instance._flush_timer, CrossSync.Future) @@ -491,7 +491,7 @@ async def test_ctor_no_flush_limits(self): assert instance._flow_control._in_flight_mutation_count == 0 assert instance._flow_control._in_flight_mutation_bytes == 0 assert instance._entries_processed_since_last_raise == 0 - await CrossSync.yield_to_event_loop() + await CrossSync.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] is None assert isinstance(instance._flush_timer, CrossSync.Future) diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py index d67a7623789e..4349c39c7bb8 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py @@ -353,7 +353,7 @@ def test_ctor_defaults(self): instance._retryable_errors == table.default_mutate_rows_retryable_errors ) - CrossSync._Sync_Impl.yield_to_event_loop() + CrossSync._Sync_Impl.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] == 5 assert isinstance(instance._flush_timer, CrossSync._Sync_Impl.Future) @@ -406,7 +406,7 @@ def test_ctor_explicit(self): assert instance._operation_timeout == operation_timeout assert instance._attempt_timeout == attempt_timeout assert instance._retryable_errors == retryable_errors - CrossSync._Sync_Impl.yield_to_event_loop() + CrossSync._Sync_Impl.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] == flush_interval assert isinstance(instance._flush_timer, CrossSync._Sync_Impl.Future) @@ -441,7 +441,7 @@ def test_ctor_no_flush_limits(self): assert instance._flow_control._in_flight_mutation_count == 0 assert instance._flow_control._in_flight_mutation_bytes == 0 assert instance._entries_processed_since_last_raise == 0 - CrossSync._Sync_Impl.yield_to_event_loop() + CrossSync._Sync_Impl.wait([instance._flush_timer]) assert flush_timer_mock.call_count == 1 assert flush_timer_mock.call_args[0][0] is None assert isinstance(instance._flush_timer, CrossSync._Sync_Impl.Future)