Skip to content

Fix Socket.SendFile test: SliceBuffers_Success #48457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/libraries/System.Net.Sockets/tests/FunctionalTests/SendFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public async Task NoFile_Succeeds(bool usePreBuffer, bool usePostBuffer)
}

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

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

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

using (client)
using (server)
{
await SendFileAsync(client, null, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread);
byte[] receiveBuffer = new byte[100];
int receivedBytes = server.Receive(receiveBuffer);
Assert.Equal(100, receivedBytes);
AssertExtensions.SequenceEqual(expected, receiveBuffer);
Fletcher32 receivedChecksum = new Fletcher32();
byte[] receiveBuffer = new byte[expected.Length];
int receivedBytes;
int totalReceived = 0;
while (totalReceived < expected.Length && (receivedBytes = server.Receive(receiveBuffer)) != 0)
{
totalReceived += receivedBytes;
receivedChecksum.Add(receiveBuffer, 0, receivedBytes);
}
Assert.Equal(expected.Length, totalReceived);
Assert.Equal(expectedChecksum, receivedChecksum.Sum);
}
}

Expand Down