marvelefe commented on code in PR #2884:
URL:
https://github.com/apache/datafusion-ballista/pull/2884#discussion_r4675939414
##########
ballista/core/src/execution_plans/distributed_query.rs:
##########
@@ -1958,4 +2058,133 @@ mod test {
"unexpected error: {err}"
);
}
+
+ /// Runs a job through the pull or push client against a scheduler that
+ /// serves `statuses`, and returns its batches and the execution metrics.
+ async fn run_job(
+ pull: bool,
+ statuses: Vec<JobStatus>,
+ ) -> (
+
datafusion::error::Result<Vec<datafusion::arrow::record_batch::RecordBatch>>,
+ Arc<ExecutionPlanMetricsSet>,
+ ) {
+ let scheduler = FakeScheduler::compatible(statuses);
+ let url = scheduler.start().await;
+ let metrics = Arc::new(ExecutionPlanMetricsSet::new());
+ let stream = submit(pull, url, metrics.clone()).await;
+ let batches = match stream {
+ Ok(stream) => stream.try_collect().await,
+ Err(e) => Err(e),
+ };
+ (batches, metrics)
+ }
+
+ fn gauge(metrics: &ExecutionPlanMetricsSet, name: &str) -> Option<usize> {
+ metrics
+ .clone_inner()
+ .iter()
+ .find_map(|metric| match metric.value() {
+ MetricValue::Gauge { name: n, gauge } if n == name =>
Some(gauge.value()),
+ _ => None,
+ })
+ }
+
+ #[tokio::test]
+ async fn pull_and_push_finish_a_successful_job_with_timing_metrics() {
+ for pull in [true, false] {
+ let (batches, metrics) =
+ run_job(pull, vec![queued(), running(), successful()]).await;
+
+ assert!(batches.unwrap().is_empty(), "pull={pull}");
+ assert_eq!(
+ gauge(&metrics, "job_execution_time_ms"),
+ Some(40),
+ "pull={pull}"
+ );
+ assert_eq!(
+ gauge(&metrics, "job_scheduling_in_ms"),
+ Some(20),
+ "pull={pull}"
+ );
+ assert!(
+ gauge(&metrics, "total_query_time_ms").is_some(),
+ "pull={pull}"
+ );
+ }
+ }
+
+ #[tokio::test]
+ async fn pull_and_push_report_a_failed_job() {
+ for pull in [true, false] {
+ let (batches, _) =
+ run_job(pull, vec![queued(), failed("divide by zero")]).await;
+
+ let err = batches.unwrap_err();
+ assert!(
+ err.to_string().contains("Job job failed: divide by zero"),
+ "pull={pull}: {err}"
+ );
+ }
+ }
+
+ #[tokio::test]
+ async fn poll_job_until_successful_returns_the_finished_job() {
+ let scheduler =
+ FakeScheduler::compatible(vec![queued(), running(), successful()]);
+ let url = scheduler.start().await;
+ let mut client = scheduler_client(url).await;
+
+ let job = poll_job_until_successful(
+ &mut client,
+ JOB_ID.into(),
+ Duration::from_millis(1),
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(job.ended_at, 70);
+ }
+
+ #[tokio::test]
+ async fn poll_job_until_successful_reports_a_failed_job() {
+ let scheduler =
+ FakeScheduler::compatible(vec![running(), failed("out of
memory")]);
+ let url = scheduler.start().await;
+ let mut client = scheduler_client(url).await;
+
+ let err = poll_job_until_successful(
+ &mut client,
+ JOB_ID.into(),
+ Duration::from_millis(1),
+ )
+ .await
+ .unwrap_err();
+
+ assert!(
+ err.to_string().contains("Job job failed: out of memory"),
+ "{err}"
+ );
+ }
+
+ #[tokio::test]
+ async fn poll_job_until_successful_rejects_pipelined_jobs() {
Review Comment:
Good callout. I've added
`poll_job_until_successful_does_not_cancel_finished_pipelined_jobs`. It covers
a Successful job with pipelined locations. The helper returns the error and
`scheduler.cancelled()` stays empty.
--
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]