diff --git a/tests/system/_helpers.py b/tests/system/_helpers.py index 5a4c7d38d..385ceaf5c 100644 --- a/tests/system/_helpers.py +++ b/tests/system/_helpers.py @@ -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) diff --git a/tests/system/conftest.py b/tests/system/conftest.py index c4c137007..26d5c785e 100644 --- a/tests/system/conftest.py +++ b/tests/system/conftest.py @@ -44,6 +44,8 @@ "parent/child/other/file32.txt", ] +ebh_bucket_iteration = 0 + @pytest.fixture(scope="session") def storage_client(): @@ -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 diff --git a/tests/system/test_bucket.py b/tests/system/test_bucket.py index 5d7495316..0fb3a2f8d 100644 --- a/tests/system/test_bucket.py +++ b/tests/system/test_bucket.py @@ -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