From c7e31227d086a13a0864c239140222de63459e2b Mon Sep 17 00:00:00 2001 From: Curt Hagenlocher Date: Mon, 2 Dec 2024 17:16:44 -0800 Subject: [PATCH] GH-44911: [C#] Choose port numbers dynamically for ArrowStreamWriterTests (#44912) ### What changes are included in this PR? `ArrowStreamWriterTests.CanWriteToNetworkStream` and `ArrowStreamWriterTests.CanWriteToNetworkStreamAsync` pick ports dynamically instead of hardcoding a static port. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. Resolves #44911. * GitHub Issue: #44911 Authored-by: Curt Hagenlocher Signed-off-by: Curt Hagenlocher --- .../ArrowStreamWriterTests.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/csharp/test/Apache.Arrow.Tests/ArrowStreamWriterTests.cs b/csharp/test/Apache.Arrow.Tests/ArrowStreamWriterTests.cs index db8369fa618e9..d4e06a91faeff 100644 --- a/csharp/test/Apache.Arrow.Tests/ArrowStreamWriterTests.cs +++ b/csharp/test/Apache.Arrow.Tests/ArrowStreamWriterTests.cs @@ -57,14 +57,15 @@ public void Ctor_LeaveOpenTrue_StreamValidOnDispose() } [Theory] - [InlineData(true, 32153)] - [InlineData(false, 32154)] - public void CanWriteToNetworkStream(bool createDictionaryArray, int port) + [InlineData(true)] + [InlineData(false)] + public void CanWriteToNetworkStream(bool createDictionaryArray) { RecordBatch originalBatch = TestData.CreateSampleRecordBatch(length: 100, createDictionaryArray: createDictionaryArray); - TcpListener listener = new TcpListener(IPAddress.Loopback, port); + TcpListener listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); + int port = ((IPEndPoint)listener.LocalEndpoint).Port; using (TcpClient sender = new TcpClient()) { @@ -92,14 +93,15 @@ public void CanWriteToNetworkStream(bool createDictionaryArray, int port) } [Theory] - [InlineData(true, 32155)] - [InlineData(false, 32156)] - public async Task CanWriteToNetworkStreamAsync(bool createDictionaryArray, int port) + [InlineData(true)] + [InlineData(false)] + public async Task CanWriteToNetworkStreamAsync(bool createDictionaryArray) { RecordBatch originalBatch = TestData.CreateSampleRecordBatch(length: 100, createDictionaryArray: createDictionaryArray); - TcpListener listener = new TcpListener(IPAddress.Loopback, port); + TcpListener listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); + int port = ((IPEndPoint)listener.LocalEndpoint).Port; using (TcpClient sender = new TcpClient()) {