From b67afe849c4876f4d1a7a6acc0e2747160fd5c9e Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Mon, 19 Aug 2024 15:07:03 -0700 Subject: [PATCH] Fix IOCP count config var test The TcpListener was being disposed too early. --- .../tests/ThreadPoolTests.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index 4d2638c11c800..7c3c215c5ee6c 100644 --- a/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -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(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(receiveBuffer), SocketFlags.None); + Assert.Equal(1, bytesRead); + done.Set(); // indicate byte received + } } }); t.IsBackground = true; @@ -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();