Skip to content

Commit

Permalink
fix: extend wait for bucket metadata consistency in system tests (#1053)
Browse files Browse the repository at this point in the history
* fix: extend wait for bucket metadata consistency in system tests

* delay in bucket access prevention test

---------

Co-authored-by: meredithslota <meredithslota@google.com>
  • Loading branch information
andrewsg and meredithslota committed Jun 2, 2023
1 parent c42f4a4 commit d78586c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion tests/system/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def delete_bucket(bucket):
retry(bucket.delete)(force=True)


def await_config_changes_propagate(sec=3):
def await_config_changes_propagate(sec=12):
# Changes to the bucket will be readable immediately after writing,
# but configuration changes may take time to propagate.
# See https://cloud.google.com/storage/docs/json_api/v1/buckets/patch
#
# The default was changed from 3 to 12 in May 2023 due to changes in bucket
# metadata handling. Note that the documentation recommends waiting "30
# seconds".
time.sleep(sec)
16 changes: 13 additions & 3 deletions tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"parent/child/other/file32.txt",
]

ebh_bucket_iteration = 0


@pytest.fixture(scope="session")
def storage_client():
Expand Down Expand Up @@ -165,12 +167,20 @@ def signing_bucket(storage_client, signing_bucket_name):
_helpers.delete_bucket(bucket)


@pytest.fixture(scope="session")
@pytest.fixture(scope="function")
def default_ebh_bucket_name():
return _helpers.unique_name("gcp-systest-default-ebh")
# Keep track of how many ebh buckets have been created so we can get a
# clean one each rerun. "unique_name" is unique per test iteration, not
# per test rerun.
global ebh_bucket_iteration
ebh_bucket_iteration += 1
return _helpers.unique_name("gcp-systest-default-ebh") + "-{}".format(
ebh_bucket_iteration
)


@pytest.fixture(scope="session")
# ebh_bucket/name are not scope=session because the bucket is modified in test.
@pytest.fixture(scope="function")
def default_ebh_bucket(storage_client, default_ebh_bucket_name):
bucket = storage_client.bucket(default_ebh_bucket_name)
bucket.default_event_based_hold = True
Expand Down
3 changes: 3 additions & 0 deletions tests/system/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,9 @@ def test_new_bucket_created_w_inherited_pap(

bucket.iam_configuration.uniform_bucket_level_access_enabled = False
bucket.patch()

_helpers.await_config_changes_propagate()

assert (
bucket.iam_configuration.public_access_prevention
== constants.PUBLIC_ACCESS_PREVENTION_ENFORCED
Expand Down

0 comments on commit d78586c

Please sign in to comment.