Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

tests: check / retry 'instance.exists' before creating database - #418

Closed
tseaver wants to merge 3 commits into
masterfrom
390-quickstart-sample-retry-instance-exists
Closed

tseaver wants to merge 3 commits into
masterfrom
390-quickstart-sample-retry-instance-exists

Conversation

@tseaver

@tseaver tseaver commented Jul 16, 2021

Copy link
Copy Markdown
Contributor

Closes #390.

@tseaver tseaver added the samples Issues that are directly related to samples. label Jul 16, 2021
@tseaver
tseaver requested review from a team, larkee and skuruppu July 16, 2021 17:03
@tseaver
tseaver requested a review from a team as a code owner July 16, 2021 17:03
@tseaver
tseaver requested review from leahecole and removed request for a team July 16, 2021 17:03
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 16, 2021
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/python-spanner API. label Jul 16, 2021

@larkee larkee left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change likely wouldn't do anything. create_instance already blocks until the instance is created via op.result(120). I think the actual fix would be to update the pytest.fixture decorator to something similar to the test_snippets setup:
https://github.com/googleapis/python-spanner/blob/master/samples/samples/snippets_test.py#L61-L77

@tseaver

tseaver commented Jul 19, 2021

Copy link
Copy Markdown
Contributor Author

@larkee The failure in the sample test (see #390) occurs here: I've certainly seen other cases where an LRO succeeds, but subsequent GET requests fail due to eventual consistency.

I think the actual fix would be to update the pytest.fixture decorator to something similar to the test_snippets setup.

The use of fixtures in that module is actually a little wonky: very few of the testcases declare their dependencies, and in fact they can't be run separately, because they rely on other testcases having run first, as I found out when trying to debug one of the failing samples last week.

$ git grep "def test" samples/samples/snippets_test.py
samples/samples/snippets_test.py:def test_create_instance(spanner_instance):
samples/samples/snippets_test.py:def test_create_instance_with_processing_units(capsys):
samples/samples/snippets_test.py:def test_create_database(database):
samples/samples/snippets_test.py:def test_create_database_with_encryption_config(capsys, spanner_instance):
samples/samples/snippets_test.py:def test_insert_data(capsys):
samples/samples/snippets_test.py:def test_delete_data(capsys):
samples/samples/snippets_test.py:def test_query_data(capsys):
samples/samples/snippets_test.py:def test_add_column(capsys):
samples/samples/snippets_test.py:def test_read_data(capsys):
samples/samples/snippets_test.py:def test_update_data(capsys):
samples/samples/snippets_test.py:def test_read_stale_data(capsys):
samples/samples/snippets_test.py:def test_read_write_transaction(capsys):
samples/samples/snippets_test.py:def test_query_data_with_new_column(capsys):
samples/samples/snippets_test.py:def test_add_index(capsys):
samples/samples/snippets_test.py:def test_query_data_with_index(capsys):
samples/samples/snippets_test.py:def test_read_data_with_index(capsys):
samples/samples/snippets_test.py:def test_add_storing_index(capsys):
samples/samples/snippets_test.py:def test_read_data_with_storing_index(capsys):
samples/samples/snippets_test.py:def test_read_only_transaction(capsys):
samples/samples/snippets_test.py:def test_add_timestamp_column(capsys):
samples/samples/snippets_test.py:def test_update_data_with_timestamp(capsys):
samples/samples/snippets_test.py:def test_query_data_with_timestamp(capsys):
samples/samples/snippets_test.py:def test_create_table_with_timestamp(capsys):
samples/samples/snippets_test.py:def test_insert_data_with_timestamp(capsys):
samples/samples/snippets_test.py:def test_write_struct_data(capsys):
samples/samples/snippets_test.py:def test_query_with_struct(capsys):
samples/samples/snippets_test.py:def test_query_with_array_of_struct(capsys):
samples/samples/snippets_test.py:def test_query_struct_field(capsys):
samples/samples/snippets_test.py:def test_query_nested_struct_field(capsys):
samples/samples/snippets_test.py:def test_insert_data_with_dml(capsys):
samples/samples/snippets_test.py:def test_log_commit_stats(capsys):
samples/samples/snippets_test.py:def test_update_data_with_dml(capsys):
samples/samples/snippets_test.py:def test_delete_data_with_dml(capsys):
samples/samples/snippets_test.py:def test_update_data_with_dml_timestamp(capsys):
samples/samples/snippets_test.py:def test_dml_write_read_transaction(capsys):
samples/samples/snippets_test.py:def test_update_data_with_dml_struct(capsys):
samples/samples/snippets_test.py:def test_insert_with_dml(capsys):
samples/samples/snippets_test.py:def test_query_data_with_parameter(capsys):
samples/samples/snippets_test.py:def test_write_with_dml_transaction(capsys):
samples/samples/snippets_test.py:def test_create_table_with_datatypes(capsys):
samples/samples/snippets_test.py:def test_insert_datatypes_data(capsys):
samples/samples/snippets_test.py:def test_query_data_with_array(capsys):
samples/samples/snippets_test.py:def test_query_data_with_bool(capsys):
samples/samples/snippets_test.py:def test_query_data_with_bytes(capsys):
samples/samples/snippets_test.py:def test_query_data_with_date(capsys):
samples/samples/snippets_test.py:def test_query_data_with_float(capsys):
samples/samples/snippets_test.py:def test_query_data_with_int(capsys):
samples/samples/snippets_test.py:def test_query_data_with_string(capsys):
samples/samples/snippets_test.py:def test_add_numeric_column(capsys):
samples/samples/snippets_test.py:def test_update_data_with_numeric(capsys):
samples/samples/snippets_test.py:def test_query_data_with_numeric_parameter(capsys):
samples/samples/snippets_test.py:def test_query_data_with_timestamp_parameter(capsys):
samples/samples/snippets_test.py:def test_query_data_with_query_options(capsys):
samples/samples/snippets_test.py:def test_create_client_with_query_options(capsys):

Most of that is because one sample wants to show setup (e.g., creating the Venues table), and other samples depend on having that setup already done. We could chose to use the pytest-dependency plugin to handle that case.

@tseaver tseaver mentioned this pull request Jul 19, 2021
5 tasks done
@tseaver

tseaver commented Jul 19, 2021

Copy link
Copy Markdown
Contributor Author

@larkee I've opened #423 to sketch out how refactoring the samples test-drivers to use shared fixtures would look.

@tseaver tseaver closed this in fc1bc56 Jul 20, 2021
@tseaver

tseaver commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

Superseded by #423.

@tseaver
tseaver deleted the 390-quickstart-sample-retry-instance-exists branch July 20, 2021 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/python-spanner API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

samples.samples.quickstart_test: test_quickstart failed

2 participants