Modify buffer overflow logic for System.Buffers.ArrayPool.Tests.ArrayPoolUnitTests.ReturnBufferWhenFullFiresDroppedDiagnosticEvent #112849
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The test 'System.Buffers.ArrayPool.Tests.ArrayPoolUnitTests.ReturnBufferWhenFullFiresDroppedDiagnosticEvent' fails on systems with cpu cores >= 32.
The test begins by renting from a SharedArrayPool 1 byte using the 'Rent' function for 1000 iterations and returning the bytes rented using the 'Return' function back to the SharedArrayPool.
The test expects that returning a large number of bytes(in this case 1000) overflows the SharedArrayPool hence dropping it. The test case fails in machines that have cpu cores greater than 32 because the capacity of the SharedArrayPool is dependent on the number of processors. It happens to be 'number of processors' * 32.
The size of the SharedArrayPool in case of 32 cpu cores would be 32*32=1024 which is greater than 1000 and hence doesn't overflow the SharedArrayPool and hence failing test case. We actualy need ('number of processors' * 32 + 2) iterations because ('number of processors' * 32 + 1) bytes would be required to overflow the buffer and the ith iteration actually caches the byte to TLA and push the (i-1)th byte to the pool. Hence ('number of processors + 32' + 1)th byte would be returned on the ('number of processors + 32' + 2)nd iteration. see link