Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify ErrorHandlingTests for browser #40659

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,40 @@ public void DeleteDirectoryAfterOpening()
}
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)]
public void VariableLengthFileNames_AllCreatableFilesAreEnumerable()
{
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
var names = new List<string>();

for (int length = 1; length < 10_000; length++) // arbitrarily large limit for the test
[Fact]
public void VariableLengthFileNames_AllCreatableFilesAreEnumerable()
{
string name = new string('a', length);
try { File.Create(Path.Join(testDirectory.FullName, name)).Dispose(); }
catch { break; }
names.Add(name);
}
Assert.InRange(names.Count, 1, int.MaxValue);
Assert.Equal(names.OrderBy(n => n), Directory.GetFiles(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
}
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
var names = new List<string>();

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40531", TestPlatforms.Browser)]
public void VariableLengthDirectoryNames_AllCreatableDirectoriesAreEnumerable()
{
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
var names = new List<string>();
var lengthCap = PlatformDetection.IsBrowser ? 256 : 10_000; // On Browser NAME_MAX is 255, otherwise arbitrarily large limit for the test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in memfs, there is no enforcement of NAME_MAX, which is 255. As a result, you'll get 9999 files, 255 of which have increasing "a" names and the rest get their names truncated.

I'm not sure if this test has much value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the test should be removed all together? If its any worth testing enumerability, changing the length upper limit still allows for that.

for (int length = 1; length < lengthCap; length++)
{
string name = new string('a', length);
try { File.Create(Path.Join(testDirectory.FullName, name)).Dispose(); }
catch { break; }
names.Add(name);
}
Assert.InRange(names.Count, 1, int.MaxValue);
Assert.Equal(names.OrderBy(n => n), Directory.GetFiles(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
}

for (int length = 1; length < 10_000; length++) // arbitrarily large limit for the test
[Fact]
public void VariableLengthDirectoryNames_AllCreatableDirectoriesAreEnumerable()
{
string name = new string('a', length);
try { Directory.CreateDirectory(Path.Join(testDirectory.FullName, name)); }
catch { break; }
names.Add(name);
DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
var names = new List<string>();

var lengthCap = PlatformDetection.IsBrowser ? 256 : 10_000; // On Browser NAME_MAX is 255, otherwise arbitrarily large limit for the test
for (int length = 1; length < lengthCap; length++)
{
string name = new string('a', length);
try { Directory.CreateDirectory(Path.Join(testDirectory.FullName, name)); }
catch { break; }
names.Add(name);
}
Assert.InRange(names.Count, 1, int.MaxValue);
Assert.Equal(names.OrderBy(n => n), Directory.GetDirectories(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
}
Assert.InRange(names.Count, 1, int.MaxValue);
Assert.Equal(names.OrderBy(n => n), Directory.GetDirectories(testDirectory.FullName).Select(n => Path.GetFileName(n)).OrderBy(n => n));
}
}
}