Skip to content

Commit 44c94b2

Browse files
committed
Use available port instead of a random port
1 parent ee89344 commit 44c94b2

File tree

1 file changed

+4
-4
lines changed
  • kotlinx-coroutines-nio/src/test/kotlin/kotlinx/coroutines/experimental/nio

1 file changed

+4
-4
lines changed

kotlinx-coroutines-nio/src/test/kotlin/kotlinx/coroutines/experimental/nio/AsyncIOTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import kotlin.test.assertEquals
1616
import kotlin.test.assertTrue
1717

1818
class AsyncIOTest {
19-
val PORT = Random().nextInt(10000) + 10000 // randomize port for this test
20-
2119
@Rule
2220
@JvmField
2321
val tmpDir = TemporaryFolder()
@@ -66,7 +64,9 @@ class AsyncIOTest {
6664
val serverChannel =
6765
AsynchronousServerSocketChannel
6866
.open()
69-
.bind(InetSocketAddress(PORT))
67+
.bind(InetSocketAddress(0))
68+
69+
val serverPort = (serverChannel.localAddress as InetSocketAddress).port
7070

7171
val c1 = launch(CommonPool) {
7272
val client = serverChannel.aAccept()
@@ -83,7 +83,7 @@ class AsyncIOTest {
8383
val connection =
8484
AsynchronousSocketChannel.open()
8585
// async calls
86-
connection.aConnect(InetSocketAddress("127.0.0.1", PORT))
86+
connection.aConnect(InetSocketAddress("127.0.0.1", serverPort))
8787
connection.aWrite(Charsets.UTF_8.encode("OK"))
8888

8989
val buffer = ByteBuffer.allocate(3)

0 commit comments

Comments
 (0)