@@ -119,11 +119,12 @@ private string GetUniqueKeyPrefix(string testName)
119119 return $ "{ TestKeyPrefix } -{ testName } -{ Guid . NewGuid ( ) . ToString ( "N" ) . Substring ( 0 , 8 ) } ";
120120 }
121121
122- private async Task < string > CreateSnapshot ( string snapshotName , IEnumerable < ConfigurationSettingsFilter > settingsToInclude , CancellationToken cancellationToken = default )
122+ private async Task < string > CreateSnapshot ( string snapshotName , IEnumerable < ConfigurationSettingsFilter > settingsToInclude , SnapshotComposition snapshotComposition , CancellationToken cancellationToken = default )
123123 {
124124 ConfigurationSnapshot snapshot = new ConfigurationSnapshot ( settingsToInclude ) ;
125125
126- snapshot . SnapshotComposition = SnapshotComposition . Key ;
126+ snapshot . SnapshotComposition = snapshotComposition ;
127+ snapshot . RetentionPeriod = TimeSpan . FromHours ( 1 ) ;
127128
128129 CreateSnapshotOperation operation = await _configClient . CreateSnapshotAsync (
129130 WaitUntil . Completed ,
@@ -186,7 +187,6 @@ private async Task CleanupStaleResources()
186187 _output . WriteLine ( $ "Checking for stale resources older than { StaleResourceThreshold } ...") ;
187188
188189 var cutoffTime = DateTimeOffset . UtcNow . Subtract ( StaleResourceThreshold ) ;
189- var cleanupTasks = new List < Task > ( ) ;
190190
191191 // Clean up stale configuration settings, snapshots, and Key Vault secrets
192192 try
@@ -214,38 +214,50 @@ private async Task CleanupStaleResources()
214214 }
215215 }
216216
217+ // Delete configuration settings sequentially to avoid 429 errors
217218 foreach ( ConfigurationSetting setting in configSettingsToCleanup )
218219 {
219- cleanupTasks . Add ( _configClient . DeleteConfigurationSettingAsync ( setting . Key , setting . Label ) ) ;
220+ await _configClient . DeleteConfigurationSettingAsync ( setting . Key , setting . Label ) ;
220221 }
221222
222223 int staleSnapshotCount = 0 ;
224+ var snapshotsToArchive = new List < string > ( ) ;
223225 AsyncPageable < ConfigurationSnapshot > snapshots = _configClient . GetSnapshotsAsync ( new SnapshotSelector ( ) ) ;
224226 await foreach ( ConfigurationSnapshot snapshot in snapshots )
225227 {
226- if ( snapshot . Name . StartsWith ( "snapshot-" + TestKeyPrefix ) && snapshot . CreatedOn < cutoffTime )
228+ if ( snapshot . Name . StartsWith ( "snapshot-" + TestKeyPrefix ) && snapshot . CreatedOn < cutoffTime && snapshot . Status == ConfigurationSnapshotStatus . Ready )
227229 {
228- cleanupTasks . Add ( _configClient . ArchiveSnapshotAsync ( snapshot . Name ) ) ;
230+ snapshotsToArchive . Add ( snapshot . Name ) ;
229231 staleSnapshotCount ++ ;
230232 }
231233 }
232234
235+ // Archive snapshots sequentially to avoid 429 errors
236+ foreach ( string snapshotName in snapshotsToArchive )
237+ {
238+ await _configClient . ArchiveSnapshotAsync ( snapshotName ) ;
239+ }
240+
233241 int staleSecretCount = 0 ;
242+ var secretsToDelete = new List < string > ( ) ;
234243 if ( _secretClient != null )
235244 {
236245 AsyncPageable < SecretProperties > secrets = _secretClient . GetPropertiesOfSecretsAsync ( ) ;
237246 await foreach ( SecretProperties secretProperties in secrets )
238247 {
239248 if ( secretProperties . Name . StartsWith ( TestKeyPrefix ) && secretProperties . CreatedOn . HasValue && secretProperties . CreatedOn . Value < cutoffTime )
240249 {
241- cleanupTasks . Add ( _secretClient . StartDeleteSecretAsync ( secretProperties . Name ) ) ;
250+ secretsToDelete . Add ( secretProperties . Name ) ;
242251 staleSecretCount ++ ;
243252 }
244253 }
245- }
246254
247- // Wait for all cleanup tasks to complete
248- await Task . WhenAll ( cleanupTasks ) ;
255+ // Delete secrets sequentially to avoid 429 errors
256+ foreach ( string secretName in secretsToDelete )
257+ {
258+ await _secretClient . StartDeleteSecretAsync ( secretName ) ;
259+ }
260+ }
249261
250262 _output . WriteLine ( $ "Cleaned up { staleConfigCount } stale configuration settings, { staleSnapshotCount } snapshots, and { staleSecretCount } secrets") ;
251263 }
@@ -332,10 +344,11 @@ private async Task SetUpSnapshotReferences(TestContext context)
332344 {
333345 if ( _configClient != null )
334346 {
335- await CreateSnapshot ( context . SnapshotName , new List < ConfigurationSettingsFilter >
347+ var settingsToInclude = new List < ConfigurationSettingsFilter >
336348 {
337349 new ConfigurationSettingsFilter ( context . KeyPrefix + ":*" )
338- } ) ;
350+ } ;
351+ await CreateSnapshot ( context . SnapshotName , settingsToInclude , SnapshotComposition . Key ) ;
339352
340353 ConfigurationSetting snapshotReferenceSetting = ConfigurationModelFactory . ConfigurationSetting (
341354 context . SnapshotReferenceKey ,
@@ -1224,7 +1237,7 @@ public async Task LoadSnapshot_RetrievesValuesFromSnapshot()
12241237 string snapshotName = $ "snapshot-{ testContext . KeyPrefix } ";
12251238
12261239 // Create a snapshot with the test keys
1227- await CreateSnapshot ( snapshotName , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext . KeyPrefix + "*" ) } ) ;
1240+ await CreateSnapshot ( snapshotName , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
12281241
12291242 // Update values after snapshot is taken to verify snapshot has original values
12301243 await _configClient . SetConfigurationSettingAsync ( new ConfigurationSetting ( $ "{ testContext . KeyPrefix } :Setting1", "UpdatedAfterSnapshot" ) ) ;
@@ -1283,8 +1296,8 @@ await _configClient.SetConfigurationSettingAsync(
12831296 string snapshotName2 = $ "snapshot-{ testContext2 . KeyPrefix } ";
12841297
12851298 // Create snapshots
1286- await CreateSnapshot ( snapshotName1 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext1 . KeyPrefix + "*" ) } ) ;
1287- await CreateSnapshot ( snapshotName2 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext2 . KeyPrefix + "*" ) } ) ;
1299+ await CreateSnapshot ( snapshotName1 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext1 . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
1300+ await CreateSnapshot ( snapshotName2 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( testContext2 . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
12881301
12891302 try
12901303 {
@@ -1326,19 +1339,11 @@ public async Task SnapshotCompositionTypes_AreHandledCorrectly()
13261339 new ConfigurationSettingsFilter ( $ "{ testContext . KeyPrefix } :*")
13271340 } ;
13281341
1329- ConfigurationSnapshot keyOnlySnapshot = new ConfigurationSnapshot ( settingsToInclude ) ;
1330-
1331- keyOnlySnapshot . SnapshotComposition = SnapshotComposition . Key ;
1332-
13331342 // Create the snapshot
1334- await _configClient . CreateSnapshotAsync ( WaitUntil . Completed , keyOnlySnapshotName , keyOnlySnapshot ) ;
1335-
1336- ConfigurationSnapshot invalidSnapshot = new ConfigurationSnapshot ( settingsToInclude ) ;
1337-
1338- invalidSnapshot . SnapshotComposition = SnapshotComposition . KeyLabel ;
1343+ await CreateSnapshot ( keyOnlySnapshotName , settingsToInclude , SnapshotComposition . Key ) ;
13391344
13401345 // Create the snapshot
1341- await _configClient . CreateSnapshotAsync ( WaitUntil . Completed , invalidCompositionSnapshotName , invalidSnapshot ) ;
1346+ await CreateSnapshot ( invalidCompositionSnapshotName , settingsToInclude , SnapshotComposition . KeyLabel ) ;
13421347
13431348 try
13441349 {
@@ -1399,12 +1404,8 @@ await _configClient.SetConfigurationSettingAsync(
13991404 new ConfigurationSettingsFilter ( $ ".appconfig.featureflag/{ testContext . KeyPrefix } *")
14001405 } ;
14011406
1402- ConfigurationSnapshot snapshot = new ConfigurationSnapshot ( settingsToInclude ) ;
1403-
1404- snapshot . SnapshotComposition = SnapshotComposition . Key ;
1405-
14061407 // Create the snapshot
1407- await _configClient . CreateSnapshotAsync ( WaitUntil . Completed , snapshotName , snapshot ) ;
1408+ await CreateSnapshot ( snapshotName , settingsToInclude , SnapshotComposition . Key ) ;
14081409
14091410 // Update feature flag to disabled after creating snapshot
14101411 await _configClient . SetConfigurationSettingAsync (
@@ -1480,9 +1481,9 @@ await _configClient.SetConfigurationSettingAsync(
14801481 string snapshot2 = $ "snapshot-{ secondContext . KeyPrefix } -2";
14811482 string snapshot3 = $ "snapshot-{ thirdContext . KeyPrefix } -3";
14821483
1483- await CreateSnapshot ( snapshot1 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( mainContext . KeyPrefix + "*" ) } ) ;
1484- await CreateSnapshot ( snapshot2 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( secondContext . KeyPrefix + "*" ) } ) ;
1485- await CreateSnapshot ( snapshot3 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( thirdContext . KeyPrefix + "*" ) } ) ;
1484+ await CreateSnapshot ( snapshot1 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( mainContext . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
1485+ await CreateSnapshot ( snapshot2 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( secondContext . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
1486+ await CreateSnapshot ( snapshot3 , new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( thirdContext . KeyPrefix + "*" ) } , SnapshotComposition . Key ) ;
14861487
14871488 try
14881489 {
@@ -1811,10 +1812,11 @@ public async Task SnapshotReference_WithKeyVaultReference()
18111812 await _configClient . SetConfigurationSettingAsync ( keyVaultRefSetting ) ;
18121813 }
18131814
1814- await CreateSnapshot ( testContext . SnapshotName , new List < ConfigurationSettingsFilter >
1815+ var settingsToInclude = new List < ConfigurationSettingsFilter >
18151816 {
18161817 new ConfigurationSettingsFilter ( testContext . KeyPrefix + "*" )
1817- } ) ;
1818+ } ;
1819+ await CreateSnapshot ( testContext . SnapshotName , settingsToInclude , SnapshotComposition . Key ) ;
18181820
18191821 ConfigurationSetting snapshotReferenceSetting = ConfigurationModelFactory . ConfigurationSetting (
18201822 testContext . SnapshotReferenceKey ,
0 commit comments