Browse Source

Reserve Server Ports in integrationTests

Previously the build would look up a server port dynamically, but since
it closed the port immediately it may not be reserved by the time jetty
started up.

We now reserve the port and do not close it till just before Jetty starts.
While there is still a race condition, it is much smaller window of time
than it was previously.
3.0.x
Rob Winch 13 years ago
parent
commit
39918b4a01
  1. 28
      samples/cas/sample/cassample.gradle

28
samples/cas/sample/cassample.gradle

@ -104,22 +104,26 @@ gradle.taskGraph.whenReady {graph ->
} }
if(graph.hasTask(integrationTest)) { if(graph.hasTask(integrationTest)) {
tasks.getByPath(':spring-security-samples-casserver:casServerOverlay').logLevel = 'ERROR' tasks.getByPath(':spring-security-samples-casserver:casServerOverlay').logLevel = 'ERROR'
jettyRunWar.additionalRuntimeJars += file("src/integration-test/resources") jettyRunWar {
additionalRuntimeJars += file("src/integration-test/resources")
daemon = true
}
jettyRunWar.daemon = true [jettyRunWar.httpConnector,jettyRunWar.httpsConnector,casServer.httpsConnector]*.metaClass*.reservePort { taskToCloseSocket ->
jettyRunWar.httpConnector.port = availablePort() def serverSocket = new ServerSocket(0)
jettyRunWar.httpsConnector.port = jettyRunWar.httpConnector.confidentialPort = availablePort() delegate.metaClass.serverSocket = serverSocket
casServer.httpsConnector.port = availablePort() delegate.port = serverSocket.localPort
taskToCloseSocket.doFirst {
serverSocket.close()
} }
} }
def casServer() { [jettyRunWar.httpConnector,jettyRunWar.httpsConnector]*.reservePort(jettyRunWar)
tasks.getByPath(':spring-security-samples-casserver:casServer') jettyRunWar.httpConnector.confidentialPort = jettyRunWar.httpsConnector.port
casServer.httpsConnector.reservePort(casServer)
}
} }
def availablePort() { def casServer() {
ServerSocket server = new ServerSocket(0) tasks.getByPath(':spring-security-samples-casserver:casServer')
int port = server.localPort
server.close()
port
} }

Loading…
Cancel
Save