Avoid OutOfMemoryException in some test environments - #45710
Conversation
| Memory<byte> memory; | ||
| try | ||
| { |
There was a problem hiding this comment.
If allocating ~2 GB is problematic, could ~1 GB also be an issue? In that case, it might be better to put the try/catch around the whole test, including the initialization of ABW and the first call to Advance.
Alternatively, maybe we should just opt to skip the test for the specific constrained devices where 1-2GB allocation is problematic (with some kind of conditional skip attribute similar to ConditionalFact(nameof(IsX64)), if possible). How much RAM is available on the Windows.Nano test machines?
There was a problem hiding this comment.
Perhaps 1GB could cause issues as well; I see other JSON inner loop tests that allocate ~300K contiguous but not up to 1GB.
| } | ||
|
|
||
| // Validate > MaxArrayLength. | ||
| output = new ArrayBufferWriter<byte>(1); |
There was a problem hiding this comment.
This is changing the semantics of the test. We should consider leaving it as is by removing this and moving the call to GetMemory below into the try-catch, or if we find this test case useful, keeping a call to GetMemory in the try-catch in addition to this.
|
|
||
| // The buffer should grow more than the 1 byte requested otherwise performance will not be usable | ||
| // between 1GB and 2GB. The current implementation maxes out the buffer size to MaxArrayLength. | ||
| Assert.Equal(MaxArrayLength - initialCapacity, memory.Length); |
There was a problem hiding this comment.
After successfully setting ABW to init capacity, verify that output.GetMemory(int.max) fails.
| Assert.Equal(MaxArrayLength - initialCapacity, memory.Length); | |
| Assert.Equal(MaxArrayLength - initialCapacity, memory.Length); | |
| Assert.Throws<OutOfMemoryException>(() => output.GetMemory(int.MaxValue)); |
| @@ -1,4 +1,8 @@ | |||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||
| | |||
There was a problem hiding this comment.
Revert unrelated changes to this .sln file?
ahsonkhan
left a comment
There was a problem hiding this comment.
Otherwise, looks good.
Fixes #43932