Matthew-DWM commented on code in PR #9364:
URL: https://github.com/apache/texera/pull/9364#discussion_r4555877046
##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/pythonworker/PythonProxyClientSpec.scala:
##########
@@ -368,6 +408,96 @@ class PythonProxyClientSpec extends AnyFlatSpec {
}
}
+ it should "keep sending after the Python side acknowledges a put late" in {
+ withClient() { fixture =>
+ // Longer than the 5 s the client used to allow for a put's ack.
+ fixture.producer.ackDelayMs = 6000L
+ fixture.producer.delayedPuts = 1
+ fixture.producer.reportedQueueSize = 11L
+ fixture.start()
+ val schema = Schema().add(new Attribute("v", AttributeType.INTEGER))
+ def frame(v: Int): Array[Tuple] =
+ Array(Tuple.builder(schema).addSequentially(Array(Int.box(v))).build())
+ val dataChannel = ChannelIdentity(clientWorkerId, controllerId,
isControl = false)
+
+ fixture.client.enqueueData(DataElement(DataFrame(frame(1)), dataChannel))
+ fixture.client.enqueueData(DataElement(DataFrame(frame(2)), dataChannel))
+ fixture.client.enqueueActorCommand(CreditUpdate())
+
+ // Everything queued behind the slow put still reaches the Python side,
in order.
+ awaitTrue(20000)(
+ fixture.loopFailure.isDefined ||
+ (fixture.producer.putsReceived.size == 2 &&
+ fixture.producer.actionsReceived.asScala.exists(_._1 == "actor"))
+ )
+ assert(fixture.loopFailure.isEmpty, s"the client loop died:
${fixture.loopFailure}")
+ assert(
+ fixture.producer.putsReceived.asScala.map(_.tuples).toVector ==
+ Vector(frame(1).toVector, frame(2).toVector)
+ )
+ // The late ack's queue size is still taken for flow control.
+ awaitTrue()(fixture.client.getQueuedCredit == 11L)
+ }
+ }
+
+ it should "stop with the Python side's error when a put is rejected" in {
+ withClient() { fixture =>
+ fixture.producer.rejectPuts = true
+ fixture.start()
+ val schema = Schema().add(new Attribute("v", AttributeType.INTEGER))
+ val tuple =
Tuple.builder(schema).addSequentially(Array(Int.box(1))).build()
+ val dataChannel = ChannelIdentity(clientWorkerId, controllerId,
isControl = false)
+
+ fixture.client.enqueueData(DataElement(DataFrame(Array(tuple)),
dataChannel))
+
+ // The loop must end with an error rather than wait forever for an ack
that never comes,
+ // and the error must say why, so the worker can report it.
+ awaitTrue()(fixture.loopFailure.isDefined)
+ val messages = Iterator
Review Comment:
Done in #9413 (16647481f): the rejected-put test now uses `causeMessages`,
like the others.
##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/pythonworker/PythonWorkflowWorkerSpec.scala:
##########
@@ -163,6 +184,150 @@ class PythonWorkflowWorkerSpec
field.getBoolean(client)
}
+ //
---------------------------------------------------------------------------
+ // Failure-reporting fixtures
+ //
---------------------------------------------------------------------------
+
+ /** Sent to the failure probe once the worker child exists. */
+ private case class Spawned(worker: ActorRef)
+
+ /**
+ * Creates one worker as its child and supervises it the way the
coordinator does: each failure
+ * goes to `failures` and the child is stopped. What the child sends its
parent (its
+ * RegisterActorRef, for one) is ignored.
+ */
+ private class FailureCapturingParent(worker: => PythonWorkflowWorker,
failures: ActorRef)
+ extends Actor {
+ override val supervisorStrategy: SupervisorStrategy = OneForOneStrategy() {
+ case e: Throwable =>
+ failures ! e
+ SupervisorStrategy.Stop
+ }
+ override def preStart(): Unit = failures !
Spawned(context.actorOf(Props(worker)))
+ override def receive: Receive = { case _ => }
+ }
+
+ /** A real worker that hands itself to the test, so the test can release its
port. */
+ private class ObservedWorker(config: WorkerConfig, held:
AtomicReference[PythonWorkflowWorker])
+ extends PythonWorkflowWorker(config) {
+ held.set(this)
+ }
+
+ /** Starts the proxy server and the (stand-in) interpreter, but no Flight
client. */
+ private class ProcessOnlyWorker(config: WorkerConfig, held:
AtomicReference[PythonWorkflowWorker])
+ extends ObservedWorker(config, held) {
+ override def initState(): Unit = {
+ invokePrivate(this, "startProxyServer")
+ invokePrivate(this, "startPythonProcess")
+ }
+ }
+
+ /**
+ * Starts only the Flight client, against a port nothing listens on, so the
client fails to
+ * connect. `process` stands in for the interpreter the worker would have
spawned.
+ */
+ private class ClientOnlyWorker(
+ config: WorkerConfig,
+ held: AtomicReference[PythonWorkflowWorker],
+ process: Option[Process]
+ ) extends ObservedWorker(config, held) {
+ override def initState(): Unit = {
+ process.foreach(setServerProcess(this, _))
+ openPort(this, freePort)
+ invokePrivate(this, "startProxyClient")
+ }
+ }
+
+ /** A process that has already exited with `code`. */
+ private class ExitedProcess(code: Int) extends StandInProcess {
+ override def isAlive(): Boolean = false
+ override def exitValue(): Int = code
+ override def destroy(): Unit = ()
+ }
+
+ private case class Supervised(
+ worker: ActorRef,
+ instance: AtomicReference[PythonWorkflowWorker],
+ failures: TestProbe
+ )
+
+ private def supervise(
+ create: AtomicReference[PythonWorkflowWorker] => PythonWorkflowWorker
+ ): Supervised = {
+ val failures = TestProbe()
+ val held = new AtomicReference[PythonWorkflowWorker]()
+ system.actorOf(Props(new FailureCapturingParent(create(held),
failures.ref)))
+ val worker = failures.expectMsgType[Spawned](10.seconds).worker
+ // The child is constructed asynchronously, after the parent has already
reported it.
+ awaitCond(held.get != null, 10.seconds)
+ Supervised(worker, held, failures)
+ }
+
+ private def invokePrivate(actor: PythonWorkflowWorker, name: String): Unit =
{
Review Comment:
Done: the three start-up methods are `private[pythonworker]`, and the spec
calls them directly.
--
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]