@@ -99,6 +99,10 @@ void SetBucketEncryptionEnforcementConfig(
9999 << create_bucket (" g-" + bucket_name, gmek_encryption)->name ()
100100 << " created with GMEK-only enforcement policy.\n " ;
101101
102+ // In GCS, a single project cannot create or delete buckets more often than
103+ // once every two seconds. We pause to avoid rate limiting.
104+ std::this_thread::sleep_for (std::chrono::seconds (2 ));
105+
102106 // Example 2: Enforce CMEK Only
103107 gcs::BucketEncryption cmek_encryption;
104108 cmek_encryption.google_managed_encryption_enforcement_config
@@ -111,6 +115,10 @@ void SetBucketEncryptionEnforcementConfig(
111115 << create_bucket (" c-" + bucket_name, cmek_encryption)->name ()
112116 << " created with CMEK-only enforcement policy.\n " ;
113117
118+ // In GCS, a single project cannot create or delete buckets more often than
119+ // once every two seconds. We pause to avoid rate limiting.
120+ std::this_thread::sleep_for (std::chrono::seconds (2 ));
121+
114122 // Example 3: Restrict CSEK (Ransomware Protection)
115123 gcs::BucketEncryption csek_encryption;
116124 csek_encryption.customer_supplied_encryption_enforcement_config
@@ -194,11 +202,14 @@ void RunAll(std::vector<std::string> const& argv) {
194202 // In GCS a single project cannot create or delete buckets more often than
195203 // once every two seconds. We will pause until that time before deleting the
196204 // buckets.
197- auto pause = std::chrono::steady_clock::now () + std::chrono::seconds (2 );
205+ auto constexpr kBucketPeriod = std::chrono::seconds (2 );
206+ auto pause = std::chrono::steady_clock::now () + kBucketPeriod ;
198207 if (!examples::UsingEmulator ()) std::this_thread::sleep_until (pause);
199208
200209 (void )examples::RemoveBucketAndContents (client, " g-" + bucket_name);
210+ if (!examples::UsingEmulator ()) std::this_thread::sleep_for (kBucketPeriod );
201211 (void )examples::RemoveBucketAndContents (client, " c-" + bucket_name);
212+ if (!examples::UsingEmulator ()) std::this_thread::sleep_for (kBucketPeriod );
202213 (void )examples::RemoveBucketAndContents (client, " rc-" + bucket_name);
203214}
204215
0 commit comments