Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnakinRaW committed Apr 7, 2024
1 parent 6d3665b commit 0487fe7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void Test_DeleteWithRetry()
Assert.Throws<IOException>(() => _fileSystem.Directory.DeleteWithRetry(dir1.FullName, false));

// https://github.com/Testably/Testably.Abstractions/issues/549
// and also https://github.com/dotnet/runtime/issues/52700
//var fs = _fileSystem.FileStream.New("test/text1.txt", FileMode.Open);
//Assert.Throws<IOException>(() => dir1.DeleteWithRetry());
//Assert.Throws<IOException>(() => _fileSystem.Directory.DeleteWithRetry(dir1.FullName));
Expand Down
56 changes: 33 additions & 23 deletions src/CommonUtilities.FileSystem/test/FileInfoExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Runtime.InteropServices;
using AnakinRaW.CommonUtilities.Testing;
using Testably.Abstractions.Testing;
using Xunit;
Expand Down Expand Up @@ -52,18 +53,24 @@ public void Test_DeleteWithRetry()
var file2 = _fileSystem.FileInfo.New("text2.txt");
file2.Attributes |= FileAttributes.ReadOnly;

var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
Assert.Throws<IOException>(() => file1.DeleteWithRetry());
Assert.Throws<IOException>(() => _fileSystem.File.DeleteWithRetry(file2.FullName));
// https://github.com/dotnet/runtime/issues/52700
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
Assert.Throws<IOException>(() => file1.DeleteWithRetry());
Assert.Throws<IOException>(() => _fileSystem.File.DeleteWithRetry(file2.FullName));

file1.Refresh();
file2.Refresh();
Assert.True(file1.Exists);
Assert.True(file2.Exists);

fs1.Dispose();
fs2.Dispose();
}

file1.Refresh();
file2.Refresh();
Assert.True(file1.Exists);
Assert.True(file2.Exists);

fs1.Dispose();
fs2.Dispose();

file1.Refresh();
file2.Refresh();
Expand All @@ -88,19 +95,22 @@ public void Test_TryDeleteWithRetry()
var file2 = _fileSystem.FileInfo.New("text2.txt");
file2.Attributes |= FileAttributes.ReadOnly;

var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
Assert.False(file1.TryDeleteWithRetry());
Assert.False(_fileSystem.File.TryDeleteWithRetry(file2.FullName));

file1.Refresh();
file2.Refresh();
Assert.True(file1.Exists);
Assert.True(file2.Exists);

fs1.Dispose();
fs2.Dispose();

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.None);
Assert.False(file1.TryDeleteWithRetry());
Assert.False(_fileSystem.File.TryDeleteWithRetry(file2.FullName));

file1.Refresh();
file2.Refresh();
Assert.True(file1.Exists);
Assert.True(file2.Exists);

fs1.Dispose();
fs2.Dispose();
}

file1.Refresh();
file2.Refresh();
Assert.True(file1.TryDeleteWithRetry());
Expand Down

0 comments on commit 0487fe7

Please sign in to comment.