Skip to content

Commit

Permalink
fix server issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullinAM committed Aug 17, 2023
1 parent b9131ce commit 911e21a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class MasterProtocolSocketHandler(
override val workerPort get() = workerListener.localPort

override fun receiveClientConnection(): Master2ClientConnection {
val socket = Socket("localhost", clientPort)
val socket = Socket()
socket.connect(InetSocketAddress("localhost", clientPort))
log.debug("Client {} connected to master {}", socket.remoteSocketAddress, socket.localSocketAddress)
return Master2ClientSocketConnection(socket)
}

Expand All @@ -76,6 +78,7 @@ class Master2ClientSocketConnection(private val socket: Socket) : Master2ClientC
}

override fun receive(): String {
log.debug("Receiving a message from {} to {}", socket.remoteSocketAddress, socket.localSocketAddress)
return reader.readLine().also {
log.debug("Master received a request $it")
}
Expand Down Expand Up @@ -111,7 +114,6 @@ class Master2WorkerSocketConnection(private val socket: Socket) : Master2WorkerC
}

override fun receive(): String {
log.debug("Receiving a message from {} to {}", socket.remoteSocketAddress, socket.localAddress)
return reader.readLine()
}

Expand All @@ -134,12 +136,12 @@ class Client2MasterSocketConnection(
override fun connect(timeout: Duration): Boolean {
writer = socket.getOutputStream().bufferedWriter()
reader = socket.getInputStream().bufferedReader()
log.debug("Connected to master")
log.debug("Client {} connected to master {}", socket.localSocketAddress, socket.remoteSocketAddress)
return true
}

override fun send(request: TestExecutionRequest) {
log.debug("Client sending a request: {} from {} to {}", request, socket.localAddress, socket.remoteSocketAddress)
log.debug("Client sending a request: {} from {} to {}", request, socket.localSocketAddress, socket.remoteSocketAddress)
val json = serializer.toJson(request)
writer.write(json)
writer.newLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ExecutorMaster(
val client = connection.receiveClientConnection()
log.debug("Master received a client connection")
launch {
client.use { handleClient(it) }
handleClient(client)
}
yield()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.time.Duration.Companion.seconds
@InternalSerializationApi
internal object ExecutorMasterController : AutoCloseable {
private lateinit var process: Process
private val controllerSocket = ServerSocket(0)
private lateinit var controllerSocket: ServerSocket
private val serializers = mutableMapOf<ClassManager, KexSerializer>()

init {
Expand All @@ -38,6 +38,7 @@ internal object ExecutorMasterController : AutoCloseable {
}

fun start(ctx: ExecutionContext) {
controllerSocket = ServerSocket(0)
val outputDir = kexConfig.outputDirectory
val executorPath = kexConfig.getPathValue("executor", "executorPath") {
Paths.get("kex-executor/target/kex-executor-0.0.1-jar-with-dependencies.jar")
Expand Down Expand Up @@ -96,6 +97,7 @@ internal object ExecutorMasterController : AutoCloseable {

override fun close() {
process.destroy()
controllerSocket.close()
}
}

Expand Down

0 comments on commit 911e21a

Please sign in to comment.