Fix packaging test use of Stream.Read (#54233)
authorStephen Toub <stoub@microsoft.com>
Wed, 16 Jun 2021 16:56:03 +0000 (12:56 -0400)
committerGitHub <noreply@github.com>
Wed, 16 Jun 2021 16:56:03 +0000 (12:56 -0400)
Read returning the number of bytes requested is not guaranteed.

src/libraries/System.IO.Packaging/tests/Tests.cs

index 386523d..8dd92b4 100644 (file)
@@ -3823,9 +3823,15 @@ namespace System.IO.Packaging.Tests
                         byte[] readBuffer = new byte[buffer.Length];
                         for (long i = 0; i < SizeInMb; i++)
                         {
-                            int actualRead = partStream.Read(readBuffer, 0, readBuffer.Length);
+                            int totalRead = 0;
+                            while (totalRead < readBuffer.Length)
+                            {
+                                int actualRead = partStream.Read(readBuffer, totalRead, readBuffer.Length - totalRead);
+                                Assert.InRange(actualRead, 1, readBuffer.Length - totalRead);
+                                totalRead += actualRead;
+                            }
 
-                            Assert.Equal(actualRead, readBuffer.Length);
+                            Assert.Equal(readBuffer.Length, totalRead);
                             Assert.True(buffer.AsSpan().SequenceEqual(readBuffer));
                         }
                     }