Fix EncryptDecrypt test (#72874)
authorDan Moseley <danmose@microsoft.com>
Tue, 26 Jul 2022 22:36:01 +0000 (16:36 -0600)
committerGitHub <noreply@github.com>
Tue, 26 Jul 2022 22:36:01 +0000 (16:36 -0600)
* Fix EncryptDecrypt test

* more retries

src/libraries/System.IO.FileSystem/tests/File/EncryptDecrypt.cs

index 0c70a04..8aa5f73 100644 (file)
@@ -71,7 +71,14 @@ namespace System.IO.Tests
                 Assert.Equal(fileContentRead, File.ReadAllText(tmpFileName));
                 Assert.Equal(FileAttributes.Encrypted, (FileAttributes.Encrypted & File.GetAttributes(tmpFileName)));
 
-                File.Decrypt(tmpFileName);
+                // Sometimes Decrypt will fail with, eg.,
+                // System.IO.IOException : The process cannot access the file '...' because it is being used by another process.
+                // Assumption is that it just needs a little more time
+                RetryHelper.Execute(() =>
+                {
+                    File.Decrypt(tmpFileName);
+                }, maxAttempts: 30, backoffFunc: null, retryWhen: e => e.GetType() == typeof(IOException));
+
                 Assert.Equal(fileContentRead, File.ReadAllText(tmpFileName));
                 Assert.NotEqual(FileAttributes.Encrypted, (FileAttributes.Encrypted & File.GetAttributes(tmpFileName)));
             }