Skip to content

Commit

Permalink
Replicate failing to open port on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Dec 2, 2022
1 parent 09e06c4 commit fdcdd8b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ jobs:
shell: bash
run: |
# test building sbtn on Windows
sbt test
sbt "-Dsbt.io.virtual=false" nativeImage
# test launcher script
echo build using JDK 8, test using JDK 8, on Windows
Expand Down
2 changes: 1 addition & 1 deletion main-command/src/main/scala/xsbt/IPC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.util.control.NonFatal
object IPC {
private val portMin = 1025
private val portMax = 65536
private val loopback = InetAddress.getByName(null)
private[xsbt] val loopback = InetAddress.getByName(null)

def client[T](port: Int)(f: IPC => T): T = ipc(new Socket(loopback, port))(f)

Expand Down
38 changes: 38 additions & 0 deletions main-command/src/test/scala/xsbt/IPCSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/

package xsbt

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import xsbt.IPC.Server

import java.net.Socket

class IPCSpec extends AnyFlatSpec {
"server" should "find free open ports and close them" in {
val openedServers = collection.mutable.Set.empty[(Server, Socket)]
val portsToTest = 1000

noException should be thrownBy {
(1 to portsToTest).foreach { _ =>
val server = IPC.unmanagedServer
openedServers.add((server, new Socket(IPC.loopback, server.port)))
}
}

openedServers.size shouldBe 1000

Thread.sleep(10000)

openedServers.foreach {
case (server, socket) =>
noException should be thrownBy socket.close()
noException should be thrownBy server.close()
}
}
}

0 comments on commit fdcdd8b

Please sign in to comment.