Skip to content

Commit

Permalink
Fix IOCP count config var test
Browse files Browse the repository at this point in the history
The TcpListener was being disposed too early.
  • Loading branch information
kouvel authored and github-actions committed Aug 19, 2024
1 parent 623b402 commit ef1eea2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,22 +1394,26 @@ static async Task RunAsyncIOTest()
var done = new AutoResetEvent(false);
// Receiver
bool stop = false;
var receiveBuffer = new byte[1];
using var listener = new TcpListener(IPAddress.Loopback, 0);
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var t = ThreadTestHelpers.CreateGuardedThread(
out Action checkForThreadErrors,
out Action waitForThread,
async () =>
{
while (true)
using (listener)
{
// Accept a connection, receive a byte
using var socket = await listener.AcceptSocketAsync();
int bytesRead =
await socket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), SocketFlags.None);
Assert.Equal(1, bytesRead);
done.Set(); // indicate byte received
while (!stop)
{
// Accept a connection, receive a byte
using var socket = await listener.AcceptSocketAsync();
int bytesRead =
await socket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), SocketFlags.None);
Assert.Equal(1, bytesRead);
done.Set(); // indicate byte received
}
}
});
t.IsBackground = true;
Expand All @@ -1427,6 +1431,9 @@ static async Task RunAsyncIOTest()
Assert.Equal(1, bytesSent);
done.CheckedWait(); // wait for byte to the received
}
stop = true;
waitForThread();
}
}).Dispose();
}, ioCompletionPortCount.ToString()).Dispose();
Expand Down

0 comments on commit ef1eea2

Please sign in to comment.