Skip to content

Commit e53803d

Browse files
authored
Fix Socket.SendFile test: SliceBuffers_Success (#48457)
* do not expect a single receive * use expected.Length * enable test
1 parent 781e039 commit e53803d

File tree

1 file changed

+12
-5
lines changed
  • src/libraries/System.Net.Sockets/tests/FunctionalTests

1 file changed

+12
-5
lines changed

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendFile.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public async Task NoFile_Succeeds(bool usePreBuffer, bool usePostBuffer)
202202
}
203203

204204
[Fact]
205-
[ActiveIssue("https://github.com/dotnet/runtime/issues/47734")]
206205
public async Task SliceBuffers_Success()
207206
{
208207
if (!SupportsSendFileSlicing) return; // The overloads under test only support sending byte[] without offset and length
@@ -215,17 +214,25 @@ public async Task SliceBuffers_Success()
215214
rnd.NextBytes(postBuffer);
216215

217216
byte[] expected = preBuffer.ToArray().Concat(postBuffer.ToArray()).ToArray();
217+
uint expectedChecksum = Fletcher32.Checksum(expected, 0, expected.Length);
218218

219219
(Socket client, Socket server) = SocketTestExtensions.CreateConnectedSocketPair();
220220

221221
using (client)
222222
using (server)
223223
{
224224
await SendFileAsync(client, null, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread);
225-
byte[] receiveBuffer = new byte[100];
226-
int receivedBytes = server.Receive(receiveBuffer);
227-
Assert.Equal(100, receivedBytes);
228-
AssertExtensions.SequenceEqual(expected, receiveBuffer);
225+
Fletcher32 receivedChecksum = new Fletcher32();
226+
byte[] receiveBuffer = new byte[expected.Length];
227+
int receivedBytes;
228+
int totalReceived = 0;
229+
while (totalReceived < expected.Length && (receivedBytes = server.Receive(receiveBuffer)) != 0)
230+
{
231+
totalReceived += receivedBytes;
232+
receivedChecksum.Add(receiveBuffer, 0, receivedBytes);
233+
}
234+
Assert.Equal(expected.Length, totalReceived);
235+
Assert.Equal(expectedChecksum, receivedChecksum.Sum);
229236
}
230237
}
231238

0 commit comments

Comments
 (0)