zozo123 commented on code in PR #59232:
URL: https://github.com/apache/spark/pull/59232#discussion_r4232086637


##########
udf/worker/grpc/src/test/scala/org/apache/spark/udf/worker/grpc/testing/ForwardingWorkerMain.scala:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.udf.worker.grpc.testing
+
+import java.io.IOException
+import java.net.{StandardProtocolFamily, UnixDomainSocketAddress}
+import java.nio.ByteBuffer
+import java.nio.channels.{ServerSocketChannel, SocketChannel}
+import java.nio.file.{Files, Paths}
+import java.util.concurrent.TimeUnit
+
+import scala.jdk.CollectionConverters._
+import scala.util.control.NonFatal
+
+/**
+ * Test-only launcher that stands in for a sandbox or container launcher. It
+ * receives the engine's `--id` and `--connection`, starts the real worker on a
+ * different socket, and forwards each engine connection to it. This is the
+ * shape a launcher has when the worker cannot bind the engine's socket itself:
+ *
+ *   java -cp <classpath> ...ForwardingWorkerMain <worker command...>
+ *     --id <id> --connection <uds-path>
+ *
+ * The inner worker exits when this launcher exits, including by `SIGKILL`.

Review Comment:
   Done in `c30ddb05`. The scaladoc now says the 2 second SIGTERM wait ends in 
SIGKILL, and that a SIGKILL of the launcher runs no hook. The inner worker 
stops because `EchoGrpcWorkerMain` watches its parent.



##########
udf/worker/grpc/src/test/scala/org/apache/spark/udf/worker/grpc/DirectGrpcDispatcherIntegrationSuite.scala:
##########
@@ -160,6 +162,65 @@ class DirectGrpcDispatcherIntegrationSuite
     assert(!socketDir.exists(), "dispatcher close should remove its socket 
directory")
   }
 
+  test("a launcher command that forwards the connection serves sessions") {
+    val launcher = ProcessCallable.newBuilder()
+      .addCommand(javaExecutable)
+      .addCommand("-cp")
+      .addCommand(javaClasspath)
+      .addCommand(classOf[ForwardingWorkerMain.type].getName.stripSuffix("$"))
+      .addAllCommand(echoRunner.getCommandList)
+      .build()
+    dispatcher = new DirectGrpcDispatcher(workerSpec(launcher))
+    val sessions = Seq.fill(2)(dispatcher.createSession(None))
+    val processes = sessions.map(workerProcess)
+    val workers = processes.flatMap(_.process.descendants().iterator().asScala)
+    val payloads = Seq(
+      ByteString.copyFrom(Array.fill[Byte](5 * 1024 * 1024)(3)),
+      ByteString.copyFromUtf8("small"))
+
+    try {
+      assert(workers.size == 2, s"each launcher should start one worker, got 
$workers")
+      sessions.zip(payloads).foreach { case (session, payload) =>
+        session.init(basicInit)
+        val input = DataRequest.newBuilder().setData(payload).build()
+        assert(session.process(Iterator.single(input), 
emptyFinish).map(_.getData).toList ==
+          List(payload))
+      }
+    } finally {
+      sessions.foreach(_.close(emptyCancel))
+    }
+
+    assert(processes.forall(!_.process.isAlive), "session close should 
terminate the launcher")
+    workers.foreach { worker =>
+      worker.onExit().get(10, TimeUnit.SECONDS)
+      assert(!worker.isAlive, s"session close should stop the launched worker 
${worker.pid}")
+    }
+  }
+
+  test("SIGKILL of the forwarding launcher stops the inner worker") {
+    val launcher = ProcessCallable.newBuilder()
+      .addCommand(javaExecutable)
+      .addCommand("-cp")
+      .addCommand(javaClasspath)
+      .addCommand(classOf[ForwardingWorkerMain.type].getName.stripSuffix("$"))
+      .addAllCommand(echoRunner.getCommandList)
+      .build()
+    dispatcher = new DirectGrpcDispatcher(workerSpec(launcher))
+    val session = dispatcher.createSession(None)
+    val process = workerProcess(session)
+    val workers = process.process.descendants().iterator().asScala.toList
+    assert(workers.size == 1, s"the launcher should start one worker, got 
$workers")
+    val worker = workers.head
+    try {
+      session.init(basicInit)
+      process.process.destroyForcibly()
+      worker.onExit().get(10, TimeUnit.SECONDS)

Review Comment:
   Done in `c30ddb05`. Both launcher waits treat Linux state `Z` as exited, so 
an unreaped zombie does not time out the test. If the worker is still running 
when the wait ends, the test calls `destroyForcibly` before failing. Both 
launcher tests passed locally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to