From ecaf304175b25ff64ef3dedc5f2a1b409dafe6c0 Mon Sep 17 00:00:00 2001 From: Zhiyuan Liang Date: Wed, 17 Sep 2025 15:53:44 +0800 Subject: [PATCH 1/4] delete kv sequentially --- .../Integration/IntegrationTests.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs index 3eeecc61..95c36eae 100644 --- a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs +++ b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs @@ -186,7 +186,6 @@ private async Task CleanupStaleResources() _output.WriteLine($"Checking for stale resources older than {StaleResourceThreshold}..."); var cutoffTime = DateTimeOffset.UtcNow.Subtract(StaleResourceThreshold); - var cleanupTasks = new List(); // Clean up stale configuration settings, snapshots, and Key Vault secrets try @@ -214,23 +213,32 @@ private async Task CleanupStaleResources() } } + // Delete configuration settings sequentially to avoid 429 errors foreach (ConfigurationSetting setting in configSettingsToCleanup) { - cleanupTasks.Add(_configClient.DeleteConfigurationSettingAsync(setting.Key, setting.Label)); + await _configClient.DeleteConfigurationSettingAsync(setting.Key, setting.Label); } int staleSnapshotCount = 0; + var snapshotsToArchive = new List(); AsyncPageable snapshots = _configClient.GetSnapshotsAsync(new SnapshotSelector()); await foreach (ConfigurationSnapshot snapshot in snapshots) { if (snapshot.Name.StartsWith("snapshot-" + TestKeyPrefix) && snapshot.CreatedOn < cutoffTime) { - cleanupTasks.Add(_configClient.ArchiveSnapshotAsync(snapshot.Name)); + snapshotsToArchive.Add(snapshot.Name); staleSnapshotCount++; } } + // Archive snapshots sequentially to avoid 429 errors + foreach (string snapshotName in snapshotsToArchive) + { + await _configClient.ArchiveSnapshotAsync(snapshotName); + } + int staleSecretCount = 0; + var secretsToDelete = new List(); if (_secretClient != null) { AsyncPageable secrets = _secretClient.GetPropertiesOfSecretsAsync(); @@ -238,14 +246,17 @@ private async Task CleanupStaleResources() { if (secretProperties.Name.StartsWith(TestKeyPrefix) && secretProperties.CreatedOn.HasValue && secretProperties.CreatedOn.Value < cutoffTime) { - cleanupTasks.Add(_secretClient.StartDeleteSecretAsync(secretProperties.Name)); + secretsToDelete.Add(secretProperties.Name); staleSecretCount++; } } - } - // Wait for all cleanup tasks to complete - await Task.WhenAll(cleanupTasks); + // Delete secrets sequentially to avoid 429 errors + foreach (string secretName in secretsToDelete) + { + await _secretClient.StartDeleteSecretAsync(secretName); + } + } _output.WriteLine($"Cleaned up {staleConfigCount} stale configuration settings, {staleSnapshotCount} snapshots, and {staleSecretCount} secrets"); } From 2db914d6e26f4d015b9418648aed86f3d441124b Mon Sep 17 00:00:00 2001 From: Zhiyuan Liang Date: Wed, 17 Sep 2025 17:51:15 +0800 Subject: [PATCH 2/4] fix snapshot creation and deletion bug --- .../Integration/IntegrationTests.cs | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs index 95c36eae..8ce74eda 100644 --- a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs +++ b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs @@ -119,11 +119,12 @@ private string GetUniqueKeyPrefix(string testName) return $"{TestKeyPrefix}-{testName}-{Guid.NewGuid().ToString("N").Substring(0, 8)}"; } - private async Task CreateSnapshot(string snapshotName, IEnumerable settingsToInclude, CancellationToken cancellationToken = default) + private async Task CreateSnapshot(string snapshotName, IEnumerable settingsToInclude, SnapshotComposition snapshotComposition, CancellationToken cancellationToken = default) { ConfigurationSnapshot snapshot = new ConfigurationSnapshot(settingsToInclude); - snapshot.SnapshotComposition = SnapshotComposition.Key; + snapshot.SnapshotComposition = snapshotComposition; + snapshot.RetentionPeriod = TimeSpan.FromMinutes(5); CreateSnapshotOperation operation = await _configClient.CreateSnapshotAsync( WaitUntil.Completed, @@ -224,7 +225,7 @@ private async Task CleanupStaleResources() AsyncPageable snapshots = _configClient.GetSnapshotsAsync(new SnapshotSelector()); await foreach (ConfigurationSnapshot snapshot in snapshots) { - if (snapshot.Name.StartsWith("snapshot-" + TestKeyPrefix) && snapshot.CreatedOn < cutoffTime) + if (snapshot.Name.StartsWith("snapshot-" + TestKeyPrefix) && snapshot.CreatedOn < cutoffTime && snapshot.Status == ConfigurationSnapshotStatus.Ready) { snapshotsToArchive.Add(snapshot.Name); staleSnapshotCount++; @@ -1337,19 +1338,11 @@ public async Task SnapshotCompositionTypes_AreHandledCorrectly() new ConfigurationSettingsFilter($"{testContext.KeyPrefix}:*") }; - ConfigurationSnapshot keyOnlySnapshot = new ConfigurationSnapshot(settingsToInclude); - - keyOnlySnapshot.SnapshotComposition = SnapshotComposition.Key; - // Create the snapshot - await _configClient.CreateSnapshotAsync(WaitUntil.Completed, keyOnlySnapshotName, keyOnlySnapshot); - - ConfigurationSnapshot invalidSnapshot = new ConfigurationSnapshot(settingsToInclude); - - invalidSnapshot.SnapshotComposition = SnapshotComposition.KeyLabel; + await CreateSnapshot(keyOnlySnapshotName, settingsToInclude, SnapshotComposition.Key); // Create the snapshot - await _configClient.CreateSnapshotAsync(WaitUntil.Completed, invalidCompositionSnapshotName, invalidSnapshot); + await CreateSnapshot(invalidCompositionSnapshotName, settingsToInclude, SnapshotComposition.KeyLabel); try { @@ -1410,12 +1403,8 @@ await _configClient.SetConfigurationSettingAsync( new ConfigurationSettingsFilter($".appconfig.featureflag/{testContext.KeyPrefix}*") }; - ConfigurationSnapshot snapshot = new ConfigurationSnapshot(settingsToInclude); - - snapshot.SnapshotComposition = SnapshotComposition.Key; - // Create the snapshot - await _configClient.CreateSnapshotAsync(WaitUntil.Completed, snapshotName, snapshot); + await CreateSnapshot(snapshotName, settingsToInclude, SnapshotComposition.Key); // Update feature flag to disabled after creating snapshot await _configClient.SetConfigurationSettingAsync( From 627be055b7b6b9e085e1f9985a5924632580b34d Mon Sep 17 00:00:00 2001 From: Zhiyuan Liang Date: Wed, 17 Sep 2025 18:04:57 +0800 Subject: [PATCH 3/4] fix --- .../Integration/IntegrationTests.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs index 8ce74eda..324b18ce 100644 --- a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs +++ b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs @@ -344,10 +344,11 @@ private async Task SetUpSnapshotReferences(TestContext context) { if (_configClient != null) { - await CreateSnapshot(context.SnapshotName, new List + var settingsToInclude = new List { new ConfigurationSettingsFilter(context.KeyPrefix + ":*") - }); + }; + await CreateSnapshot(context.SnapshotName, settingsToInclude, SnapshotComposition.Key); ConfigurationSetting snapshotReferenceSetting = ConfigurationModelFactory.ConfigurationSetting( context.SnapshotReferenceKey, @@ -1236,7 +1237,7 @@ public async Task LoadSnapshot_RetrievesValuesFromSnapshot() string snapshotName = $"snapshot-{testContext.KeyPrefix}"; // Create a snapshot with the test keys - await CreateSnapshot(snapshotName, new List { new ConfigurationSettingsFilter(testContext.KeyPrefix + "*") }); + await CreateSnapshot(snapshotName, new List { new ConfigurationSettingsFilter(testContext.KeyPrefix + "*") }, SnapshotComposition.Key); // Update values after snapshot is taken to verify snapshot has original values await _configClient.SetConfigurationSettingAsync(new ConfigurationSetting($"{testContext.KeyPrefix}:Setting1", "UpdatedAfterSnapshot")); @@ -1295,8 +1296,8 @@ await _configClient.SetConfigurationSettingAsync( string snapshotName2 = $"snapshot-{testContext2.KeyPrefix}"; // Create snapshots - await CreateSnapshot(snapshotName1, new List { new ConfigurationSettingsFilter(testContext1.KeyPrefix + "*") }); - await CreateSnapshot(snapshotName2, new List { new ConfigurationSettingsFilter(testContext2.KeyPrefix + "*") }); + await CreateSnapshot(snapshotName1, new List { new ConfigurationSettingsFilter(testContext1.KeyPrefix + "*") }, SnapshotComposition.Key); + await CreateSnapshot(snapshotName2, new List { new ConfigurationSettingsFilter(testContext2.KeyPrefix + "*") }, SnapshotComposition.Key); try { @@ -1480,9 +1481,9 @@ await _configClient.SetConfigurationSettingAsync( string snapshot2 = $"snapshot-{secondContext.KeyPrefix}-2"; string snapshot3 = $"snapshot-{thirdContext.KeyPrefix}-3"; - await CreateSnapshot(snapshot1, new List { new ConfigurationSettingsFilter(mainContext.KeyPrefix + "*") }); - await CreateSnapshot(snapshot2, new List { new ConfigurationSettingsFilter(secondContext.KeyPrefix + "*") }); - await CreateSnapshot(snapshot3, new List { new ConfigurationSettingsFilter(thirdContext.KeyPrefix + "*") }); + await CreateSnapshot(snapshot1, new List { new ConfigurationSettingsFilter(mainContext.KeyPrefix + "*") }, SnapshotComposition.Key); + await CreateSnapshot(snapshot2, new List { new ConfigurationSettingsFilter(secondContext.KeyPrefix + "*") }, SnapshotComposition.Key); + await CreateSnapshot(snapshot3, new List { new ConfigurationSettingsFilter(thirdContext.KeyPrefix + "*") }, SnapshotComposition.Key); try { @@ -1811,10 +1812,11 @@ public async Task SnapshotReference_WithKeyVaultReference() await _configClient.SetConfigurationSettingAsync(keyVaultRefSetting); } - await CreateSnapshot(testContext.SnapshotName, new List + var settingsToInclude = new List { new ConfigurationSettingsFilter(testContext.KeyPrefix + "*") - }); + }; + await CreateSnapshot(testContext.SnapshotName, settingsToInclude, SnapshotComposition.Key); ConfigurationSetting snapshotReferenceSetting = ConfigurationModelFactory.ConfigurationSetting( testContext.SnapshotReferenceKey, From 533481597ab72dd0edd5c4da5109513b24528f28 Mon Sep 17 00:00:00 2001 From: Zhiyuan Liang Date: Wed, 17 Sep 2025 18:16:31 +0800 Subject: [PATCH 4/4] update retention period --- .../Tests.AzureAppConfiguration/Integration/IntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs index 324b18ce..b7be4f9b 100644 --- a/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs +++ b/tests/Tests.AzureAppConfiguration/Integration/IntegrationTests.cs @@ -124,7 +124,7 @@ private async Task CreateSnapshot(string snapshotName, IEnumerable