Skip to content
Snippets Groups Projects
Commit 856156b4 authored by Andrew Or's avatar Andrew Or
Browse files

[SPARK-3555] Fix UISuite race condition


The test "jetty selects different port under contention" is flaky.

If another process binds to 4040 before the test starts, then the first server we start there will fail, and the subsequent servers we start thereafter may successfully bind to 4040 if it was released between the servers starting. Instead, we should just let Java find a random free port for us and hold onto it for the duration of the test.

Author: Andrew Or <andrewor14@gmail.com>

Closes #2418 from andrewor14/fix-port-contention and squashes the following commits:

0cd4974 [Andrew Or] Stop them servers
a7071fe [Andrew Or] Pick random port instead of 4040

(cherry picked from commit 0a7091e6)
Signed-off-by: default avatarAndrew Or <andrewor14@gmail.com>
parent 75158a7e
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,6 @@ import scala.io.Source
import scala.language.postfixOps
import scala.util.{Failure, Success, Try}
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.ServletContextHandler
import org.scalatest.FunSuite
import org.scalatest.concurrent.Eventually._
......@@ -95,14 +94,8 @@ class UISuite extends FunSuite {
}
test("jetty selects different port under contention") {
val startPort = 4040
val server = new Server(startPort)
Try { server.start() } match {
case Success(s) =>
case Failure(e) =>
// Either case server port is busy hence setup for test complete
}
val server = new ServerSocket(0)
val startPort = server.getLocalPort
val serverInfo1 = JettyUtils.startJettyServer(
"0.0.0.0", startPort, Seq[ServletContextHandler](), new SparkConf)
val serverInfo2 = JettyUtils.startJettyServer(
......@@ -113,6 +106,9 @@ class UISuite extends FunSuite {
assert(boundPort1 != startPort)
assert(boundPort2 != startPort)
assert(boundPort1 != boundPort2)
serverInfo1.server.stop()
serverInfo2.server.stop()
server.close()
}
test("jetty binds to port 0 correctly") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment