Skip to content

Commit fe0cfd5

Browse files
github-actions[bot]Koundinya Veluri
and
Koundinya Veluri
authored
Fix IOCP count config var test (#106669)
The TcpListener was being disposed too early. Co-authored-by: Koundinya Veluri <[email protected]>
1 parent 0bf8d1e commit fe0cfd5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1394,22 +1394,26 @@ static async Task RunAsyncIOTest()
13941394
var done = new AutoResetEvent(false);
13951395

13961396
// Receiver
1397+
bool stop = false;
13971398
var receiveBuffer = new byte[1];
1398-
using var listener = new TcpListener(IPAddress.Loopback, 0);
1399+
var listener = new TcpListener(IPAddress.Loopback, 0);
13991400
listener.Start();
14001401
var t = ThreadTestHelpers.CreateGuardedThread(
14011402
out Action checkForThreadErrors,
14021403
out Action waitForThread,
14031404
async () =>
14041405
{
1405-
while (true)
1406+
using (listener)
14061407
{
1407-
// Accept a connection, receive a byte
1408-
using var socket = await listener.AcceptSocketAsync();
1409-
int bytesRead =
1410-
await socket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), SocketFlags.None);
1411-
Assert.Equal(1, bytesRead);
1412-
done.Set(); // indicate byte received
1408+
while (!stop)
1409+
{
1410+
// Accept a connection, receive a byte
1411+
using var socket = await listener.AcceptSocketAsync();
1412+
int bytesRead =
1413+
await socket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), SocketFlags.None);
1414+
Assert.Equal(1, bytesRead);
1415+
done.Set(); // indicate byte received
1416+
}
14131417
}
14141418
});
14151419
t.IsBackground = true;
@@ -1427,6 +1431,9 @@ static async Task RunAsyncIOTest()
14271431
Assert.Equal(1, bytesSent);
14281432
done.CheckedWait(); // wait for byte to the received
14291433
}
1434+
1435+
stop = true;
1436+
waitForThread();
14301437
}
14311438
}).Dispose();
14321439
}, ioCompletionPortCount.ToString()).Dispose();

0 commit comments

Comments
 (0)