Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e51fd7e

Browse files
committed
Address PR feedback
Also added a few additional tests.
1 parent 803180f commit e51fd7e

7 files changed

+216
-67
lines changed

src/Common/tests/System/IO/TempFile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void Dispose()
3535

3636
private void DeleteFile()
3737
{
38-
File.Delete(Path);
38+
try { File.Delete(Path); }
39+
catch { /* Ignore exceptions on disposal paths */ }
3940
}
4041
}
4142
}

src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public void FileAccessAndMapAccessCombinations_Valid(FileAccess fileAccess, Memo
117117
/// Tests various values of FileAccess used to construct a FileStream and MemoryMappedFileAccess used
118118
/// to construct a map over that stream on Windows. The combinations should all be invalid, resulting in exception.
119119
/// </summary>
120-
[Theory, PlatformSpecific(PlatformID.Windows)]
120+
[PlatformSpecific(PlatformID.Windows)]
121+
[Theory]
121122
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadWrite)]
122123
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadExecute)]
123124
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadWriteExecute)]
@@ -143,7 +144,8 @@ public void FileAccessAndMapAccessCombinations_Invalid_Windows(FileAccess fileAc
143144
/// Tests various values of FileAccess used to construct a FileStream and MemoryMappedFileAccess used
144145
/// to construct a map over that stream on Unix. The combinations should all be invalid, resulting in exception.
145146
/// </summary>
146-
[Theory, PlatformSpecific(PlatformID.AnyUnix)]
147+
[PlatformSpecific(PlatformID.AnyUnix)]
148+
[Theory]
147149
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadWrite)]
148150
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadExecute)]
149151
[InlineData(FileAccess.Read, MemoryMappedFileAccess.ReadWriteExecute)]
@@ -188,7 +190,8 @@ public void InvalidArguments_MapName()
188190
/// <summary>
189191
/// Test to verify that map names are left unsupported on Unix.
190192
/// </summary>
191-
[Theory, PlatformSpecific(PlatformID.AnyUnix)]
193+
[PlatformSpecific(PlatformID.AnyUnix)]
194+
[Theory]
192195
[MemberData("CreateValidMapNames")]
193196
public void MapNamesNotSupported_Unix(string mapName)
194197
{
@@ -593,7 +596,8 @@ public void FileInUse()
593596
/// <summary>
594597
/// Test the exceptional behavior of *Execute access levels.
595598
/// </summary>
596-
[Theory, PlatformSpecific(PlatformID.Windows)] // Unix model for executable differs from Windows
599+
[PlatformSpecific(PlatformID.Windows)] // Unix model for executable differs from Windows
600+
[Theory]
597601
[InlineData(MemoryMappedFileAccess.ReadExecute)]
598602
[InlineData(MemoryMappedFileAccess.ReadWriteExecute)]
599603
public void FileNotOpenedForExecute(MemoryMappedFileAccess access)
@@ -756,7 +760,7 @@ public void FileSizeExpandsToCapacity()
756760
MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, null, InitialCapacity * 2).Dispose();
757761
using (FileStream fs = File.OpenRead(file.Path))
758762
{
759-
Assert.Equal(512, fs.Length);
763+
Assert.Equal(InitialCapacity * 2, fs.Length);
760764
}
761765

762766
// Do the same thing again but with a FileStream.
@@ -771,7 +775,8 @@ public void FileSizeExpandsToCapacity()
771775
/// <summary>
772776
/// Test the exceptional behavior when attempting to create a map so large it's not supported.
773777
/// </summary>
774-
[Fact, PlatformSpecific(PlatformID.Windows | PlatformID.Linux)] // Because of the file-based backing, OS X pops up a warning dialog about being out-of-space (even though we clean up immediately)
778+
[PlatformSpecific(~PlatformID.OSX)] // Because of the file-based backing, OS X pops up a warning dialog about being out-of-space (even though we clean up immediately)
779+
[Fact]
775780
public void TooLargeCapacity()
776781
{
777782
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.CreateNew))
@@ -784,7 +789,8 @@ public void TooLargeCapacity()
784789
/// Test to verify map names are handled appropriately, causing a conflict when they're active but
785790
/// reusable in a sequential manner.
786791
/// </summary>
787-
[Theory, PlatformSpecific(PlatformID.Windows)]
792+
[PlatformSpecific(PlatformID.Windows)]
793+
[Theory]
788794
[MemberData("CreateValidMapNames")]
789795
public void ReusingNames_Windows(string name)
790796
{

src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public void InvalidArguments_Inheritability(HandleInheritability inheritability)
8686
/// <summary>
8787
/// Test the exceptional behavior when attempting to create a map so large it's not supported.
8888
/// </summary>
89-
[Fact, PlatformSpecific(PlatformID.Windows)]
89+
[PlatformSpecific(PlatformID.Windows)]
90+
[Fact]
9091
public void TooLargeCapacity_Windows()
9192
{
9293
if (IntPtr.Size == 4)
@@ -102,7 +103,8 @@ public void TooLargeCapacity_Windows()
102103
/// <summary>
103104
/// Test the exceptional behavior when attempting to create a map so large it's not supported.
104105
/// </summary>
105-
[Fact, PlatformSpecific(PlatformID.Linux)] // Because of the file-based backing, OS X pops up a warning dialog about being out-of-space (even though we clean up immediately)
106+
[PlatformSpecific(PlatformID.AnyUnix & ~PlatformID.OSX)] // Because of the file-based backing, OS X pops up a warning dialog about being out-of-space (even though we clean up immediately)
107+
[Fact]
106108
public void TooLargeCapacity_Unix()
107109
{
108110
// On Windows we fail with too large a capacity as part of the CreateNew call.
@@ -122,7 +124,8 @@ public void TooLargeCapacity_Unix()
122124
/// <summary>
123125
/// Test to verify that map names are left unsupported on Unix.
124126
/// </summary>
125-
[Theory, PlatformSpecific(PlatformID.AnyUnix)]
127+
[PlatformSpecific(PlatformID.AnyUnix)]
128+
[Theory]
126129
[MemberData("CreateValidMapNames")]
127130
public void MapNamesNotSupported_Unix(string mapName)
128131
{
@@ -134,7 +137,8 @@ public void MapNamesNotSupported_Unix(string mapName)
134137
/// <summary>
135138
/// Test to verify a variety of map names work correctly on Windows.
136139
/// </summary>
137-
[Theory, PlatformSpecific(PlatformID.Windows)]
140+
[PlatformSpecific(PlatformID.Windows)]
141+
[Theory]
138142
[MemberData("CreateValidMapNames")]
139143
[InlineData(null)]
140144
public void ValidMapNames_Windows(string name)
@@ -157,7 +161,8 @@ public void ValidMapNames_Windows(string name)
157161
/// Test to verify map names are handled appropriately, causing a conflict when they're active but
158162
/// reusable in a sequential manner.
159163
/// </summary>
160-
[Theory, PlatformSpecific(PlatformID.Windows)]
164+
[PlatformSpecific(PlatformID.Windows)]
165+
[Theory]
161166
[MemberData("CreateValidMapNames")]
162167
public void ReusingNames_Windows(string name)
163168
{
@@ -250,7 +255,8 @@ public static IEnumerable<object[]> MemberData_ValidArgumentCombinations(
250255
/// <summary>
251256
/// Test to verify that two unrelated maps don't share data.
252257
/// </summary>
253-
[Theory, PlatformSpecific(PlatformID.Windows)]
258+
[PlatformSpecific(PlatformID.Windows)]
259+
[Theory]
254260
[MemberData("CreateValidMapNames")]
255261
[InlineData(null)]
256262
public void DataNotPersistedBetweenMaps_Windows(string name)
@@ -302,20 +308,36 @@ public void ManyConcurrentMaps()
302308
/// <summary>
303309
/// Test to verify expected capacity with regards to page size and automatically rounding up to the nearest.
304310
/// </summary>
311+
[PlatformSpecific(PlatformID.Windows)]
305312
[Fact]
306-
public void RoundedUpCapacity()
313+
public void RoundedUpCapacity_Windows()
307314
{
308315
// On both Windows and Unix, capacity is rounded up to the nearest page size. However,
309316
// the amount of capacity actually usable by the developer is supposed to be limited
310317
// to that specified. That's not currently the case with the MMF APIs on Windows;
311318
// it is the case on Unix.
312-
int specifiedCapacity = 1;
313-
using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, specifiedCapacity))
319+
const int CapacityLessThanPageSize = 1;
320+
using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, CapacityLessThanPageSize))
321+
using (MemoryMappedViewAccessor acc = mmf.CreateViewAccessor())
322+
{
323+
Assert.Equal(s_pageSize.Value, acc.Capacity);
324+
}
325+
}
326+
327+
/// <summary>
328+
/// Test to verify expected capacity with regards to page size and automatically rounding up to the nearest.
329+
/// </summary>
330+
[PlatformSpecific(PlatformID.AnyUnix)]
331+
[Fact]
332+
public void RoundedUpCapacity_Unix()
333+
{
334+
// The capacity of the view should match the capacity specified when creating the map,
335+
// even though under the covers the map's capacity is rounded up to the nearest page size.
336+
const int CapacityLessThanPageSize = 1;
337+
using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(null, CapacityLessThanPageSize))
314338
using (MemoryMappedViewAccessor acc = mmf.CreateViewAccessor())
315339
{
316-
Assert.Equal(
317-
Interop.IsWindows ? s_pageSize.Value : specifiedCapacity,
318-
acc.Capacity);
340+
Assert.Equal(CapacityLessThanPageSize, acc.Capacity);
319341
}
320342
}
321343

0 commit comments

Comments
 (0)