juliomax commented on code in PR #2894:
URL:
https://github.com/apache/datafusion-ballista/pull/2894#discussion_r4645639518
##########
ballista/executor/src/executor_process.rs:
##########
@@ -1570,6 +1635,371 @@ mod tests {
drop(listener);
}
+ #[test]
+ fn resolve_vcores_zero_uses_available_parallelism() {
+ let config = ExecutorProcessConfig {
+ vcores: 0,
+ ..ExecutorProcessConfig::default()
+ };
+
+ assert_eq!(
+ super::resolve_vcores(&config),
+ std::thread::available_parallelism().unwrap().get()
+ );
+ }
+
+ #[test]
+ fn resolve_vcores_explicit_is_kept() {
+ let config = ExecutorProcessConfig {
+ vcores: 3,
+ ..ExecutorProcessConfig::default()
+ };
+
+ assert_eq!(super::resolve_vcores(&config), 3);
+ }
+
+ #[tokio::test]
+ async fn shuffle_cleaner_removes_expired_job_dirs_and_stops_on_shutdown() {
+ let work_dir = TempDir::new().unwrap();
+ let job_dir = work_dir.path().join("job_id");
+ fs::create_dir(&job_dir).unwrap();
+ File::create(job_dir.join("tmp.csv"))
+ .expect("creating temp file")
+ .write_all(b"data")
+ .expect("writing data");
+
+ let mut notifier = ShutdownNotifier::new();
+ super::spawn_shuffle_cleaner(¬ifier,
work_dir.path().to_str().unwrap(), 1, 1);
+
+ tokio::time::timeout(Duration::from_secs(10), async {
+ while job_dir.exists() {
+ tokio::time::sleep(Duration::from_millis(100)).await;
+ }
+ })
+ .await
+ .expect("expired job dir was never cleaned");
+
+ // The cleaner holds a completion sender until it sees the shutdown
+ // signal, so the receiver only completes once the cleaner has stopped.
+ let _ = notifier.notify_shutdown.send(());
+ drop(notifier.shutdown_complete_tx);
+ tokio::time::timeout(
+ Duration::from_secs(5),
+ notifier.shutdown_complete_rx.recv(),
+ )
+ .await
+ .expect("shuffle cleaner did not stop on shutdown");
+ }
+
+ #[tokio::test]
+ async fn stop_request_ends_the_wait_without_notifying_the_scheduler() {
+ let mut handlers = FuturesUnordered::new();
+ handlers.push(tokio::spawn(async {
+ std::future::pending::<Result<(), BallistaError>>().await
+ }));
+ let (stop_send, mut stop_recv) =
tokio::sync::mpsc::channel::<bool>(10);
+ stop_send.send(true).await.unwrap();
+
+ let outcome = tokio::time::timeout(
+ Duration::from_secs(5),
+ super::run_until_shutdown(&mut handlers, &mut stop_recv),
+ )
+ .await
+ .expect("a stop request did not end the wait");
+
+ assert_eq!(outcome, (false, String::new()));
+ }
+
+ #[tokio::test]
+ async fn failed_service_ends_the_wait_and_notifies_the_scheduler() {
+ let mut handlers = FuturesUnordered::new();
+ handlers.push(tokio::spawn(async {
+ Err::<(),
BallistaError>(BallistaError::General("boom".to_string()))
+ }));
+ let (_stop_send, mut stop_recv) =
tokio::sync::mpsc::channel::<bool>(10);
+
+ let (notify_scheduler, reason) = tokio::time::timeout(
+ Duration::from_secs(5),
+ super::run_until_shutdown(&mut handlers, &mut stop_recv),
+ )
+ .await
+ .expect("a failed service did not end the wait");
+
+ assert!(notify_scheduler);
+ assert!(
+ reason.starts_with("executor services stopped with reason Err("),
+ "unexpected reason: {reason}"
+ );
+ assert!(reason.contains("boom"), "unexpected reason: {reason}");
+ }
+
+ /// Reserves a local port and releases it, so nothing listens there.
+ fn unused_local_port() -> u16 {
+ std::net::TcpListener::bind("127.0.0.1:0")
+ .unwrap()
+ .local_addr()
+ .unwrap()
+ .port()
+ }
+
+ type GrpcResult<T> = std::result::Result<Response<T>, Status>;
+
+ fn not_called<T>() -> GrpcResult<T> {
+ Err(Status::unimplemented("not called by a pull-based executor"))
+ }
+
+ /// A scheduler that answers what a pull-based executor asks of it, and
+ /// never has any work to hand out.
+ struct IdleScheduler;
+
+ #[tonic::async_trait]
+ impl SchedulerGrpc for IdleScheduler {
+ type ExecuteQueryPushStream = BoxStream<GetJobStatusResult>;
+
+ async fn poll_work(
+ &self,
+ _: Request<PollWorkParams>,
+ ) -> GrpcResult<PollWorkResult> {
+ Ok(Response::new(PollWorkResult {
+ tasks: vec![],
+ jobs_to_clean: vec![],
+ }))
+ }
+
+ async fn heart_beat_from_executor(
+ &self,
+ _: Request<HeartBeatParams>,
+ ) -> GrpcResult<HeartBeatResult> {
+ Ok(Response::new(HeartBeatResult::default()))
+ }
+
+ async fn executor_stopped(
+ &self,
+ _: Request<ExecutorStoppedParams>,
+ ) -> GrpcResult<ExecutorStoppedResult> {
+ Ok(Response::new(ExecutorStoppedResult::default()))
+ }
+
+ async fn register_executor(
+ &self,
+ _: Request<RegisterExecutorParams>,
+ ) -> GrpcResult<RegisterExecutorResult> {
+ not_called()
+ }
+
+ async fn update_task_status(
+ &self,
+ _: Request<UpdateTaskStatusParams>,
+ ) -> GrpcResult<UpdateTaskStatusResult> {
+ not_called()
+ }
+
+ async fn create_update_session(
+ &self,
+ _: Request<CreateUpdateSessionParams>,
+ ) -> GrpcResult<CreateUpdateSessionResult> {
+ not_called()
+ }
+
+ async fn remove_session(
+ &self,
+ _: Request<RemoveSessionParams>,
+ ) -> GrpcResult<RemoveSessionResult> {
+ not_called()
+ }
+
+ async fn execute_query_push(
+ &self,
+ _: Request<ExecuteQueryParams>,
+ ) -> GrpcResult<Self::ExecuteQueryPushStream> {
+ not_called()
+ }
+
+ async fn execute_query(
+ &self,
+ _: Request<ExecuteQueryParams>,
+ ) -> GrpcResult<ExecuteQueryResult> {
+ not_called()
+ }
+
+ async fn get_job_status(
+ &self,
+ _: Request<GetJobStatusParams>,
+ ) -> GrpcResult<GetJobStatusResult> {
+ not_called()
+ }
+
+ async fn get_job_metrics(
+ &self,
+ _: Request<GetJobMetricsParams>,
+ ) -> GrpcResult<GetJobMetricsResult> {
+ not_called()
+ }
+
+ async fn cancel_job(
+ &self,
+ _: Request<CancelJobParams>,
+ ) -> GrpcResult<CancelJobResult> {
+ not_called()
+ }
+
+ async fn clean_job_data(
+ &self,
+ _: Request<CleanJobDataParams>,
+ ) -> GrpcResult<CleanJobDataResult> {
+ not_called()
+ }
+ }
+
+ /// Runs a pull-based executor against an idle scheduler, with the given
+ /// clean-up interval and `work_dir` as its work directory, until it shuts
+ /// itself down. The shutdown comes from its Flight port being taken, which
+ /// stops a service right after startup; it then goes through the normal
+ /// graceful shutdown path, which runs to the end with the scheduler.
+ ///
+ /// This sets the process-wide `TERMINATING` flag, which no other unit test
Review Comment:
Done in c311be9f. A small drop guard resets the flag, so it also happens if
the helper panics.
--
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]