This is an automated email from the ASF dual-hosted git repository.

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new dc196398 [SPARK-61385][CONNECT][TESTS] Run the tests of the execution 
hook without a server on a client that does not retry, so that they do not wait 
10 minutes for the plan compression lookup
dc196398 is described below

commit dc19639880112c8706b801e785c25100e6520b9b
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Wed Nov 11 07:34:24 2026 +0900

    [SPARK-61385][CONNECT][TESTS] Run the tests of the execution hook without a 
server on a client that does not retry, so that they do not wait 10 minutes for 
the plan compression lookup
    
    ### What changes were proposed in this pull request?
    
    [SPARK-61385](https://issues.apache.org/jira/browse/SPARK-61385): Run the 
two offline tests of the execution hook in the crate, on a session of a dead 
port whose client does not retry (`RetryPolicy::no_retries()`, as the tests of 
the streaming module do). They were 
`the_error_of_a_hook_is_the_error_of_the_execution` and 
`a_cleared_or_replaced_hook_is_not_called` in 
`crates/spark-connect/tests/execute_plan_hook.rs`. They move to a new 
`execute_plan_hook_tests` module at the end of `cra [...]
    
    ### Why are the changes needed?
    
    Since SPARK-61263 (#445, plan compression), the first plan of a session 
reads the plan compression confs of the server with a `Config` call before the 
hook runs, as PySpark's `_get_plan_compression_threshold_and_algorithm` does. 
The two tests used `sc://127.0.0.1:1` with the default retry policy, so that 
`Config` call was retried for its whole backoff before the hook ran. The test 
binary has taken 639 s since then; it took 0.00 s before.
    
    CI runs it in several jobs. On master at 729a7a36:
    
    | Job | `execute_plan_hook` |
    |---|---|
    | Rust build and test (stable) | 639 s, twice |
    | Rust checks | 639 s |
    | WASM UDF feature | 639 s |
    | Measure and publish coverage badges | 639 s |
    | Rust behavioral e2e (one test at a time) | 1278 s |
    
    "Rust build and test (stable)" took 7.1 minutes at aad559aa, the last full 
run before SPARK-61263, and 34.7 minutes at 2c768214, the first one after it.
    
    The client's behavior is not changed. PySpark retries that `Config` call 
too, and a session of a dead server waits for the retries in both.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No, test-only.
    
    ### How was this patch tested?
    
    - `cargo test -p apache-spark-connect --release --lib 
execute_plan_hook_tests`: both tests pass in 0.00 s.
    - `cargo test -p apache-spark-connect --release --test execute_plan_hook` 
with `SPARK_REMOTE` set to a local Spark 4.3.0 server: the remaining test 
passes.
    - The build of all the tests of the crate, without warnings, and `cargo fmt 
--all --check`. Clippy reports nothing in the changed lines.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    This pull request and its description were written by Isaac.
    
    Closes #473 from HyukjinKwon/SPARK-61385-hook-tests-no-retries.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/spark-connect/src/session.rs             | 53 +++++++++++++++++++++++++
 crates/spark-connect/tests/execute_plan_hook.rs | 49 +----------------------
 2 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/crates/spark-connect/src/session.rs 
b/crates/spark-connect/src/session.rs
index 9b1bb630..affdd019 100644
--- a/crates/spark-connect/src/session.rs
+++ b/crates/spark-connect/src/session.rs
@@ -4058,3 +4058,56 @@ mod tests {
         assert_eq!(spark.server_session_id(), None);
     }
 }
+
+/// The hook of the executions without a server: a session of a dead port 
whose requests are not
+/// retried, since the plan compression of the first plan reads the confs of 
the server before
+/// the hook runs, as PySpark does, and the default retry policy retries that 
read for minutes.
+#[cfg(test)]
+mod execute_plan_hook_tests {
+    use super::*;
+
+    fn unreachable_session_without_retries() -> SparkSession {
+        let builder = ChannelBuilder::parse("sc://127.0.0.1:1").expect("valid 
URL");
+        let mut client =
+            block_on(SparkConnectClient::connect(&builder)).expect("failed to 
build client");
+        
client.set_retry_policy(spark_connect_core::retries::RetryPolicy::no_retries());
+        SparkSession::new(client)
+    }
+
+    #[test]
+    fn the_error_of_a_hook_is_the_error_of_the_execution() {
+        let session = unreachable_session_without_retries();
+        let seen: Arc<Mutex<Vec<proto::ExecutePlanRequest>>> = Arc::default();
+        let requests = Arc::clone(&seen);
+        let hook: ExecutePlanHook = Arc::new(move |request| {
+            requests.lock().unwrap().push(request);
+            Err(SparkError::value_msg("the hook failed"))
+        });
+        session.set_execute_plan_hook(Some(hook));
+        let error = session.range(3).unwrap().collect().unwrap_err();
+        assert!(error.to_string().contains("the hook failed"), "{error}");
+        let seen = seen.lock().unwrap();
+        assert_eq!(seen.len(), 1);
+        assert_eq!(seen[0].session_id, session.session_id());
+        assert!(seen[0].operation_id.is_some());
+        assert!(seen[0].plan.is_some());
+    }
+
+    #[test]
+    fn a_cleared_or_replaced_hook_is_not_called() {
+        let session = unreachable_session_without_retries();
+        let calls = Arc::new(Mutex::new(0));
+        let counted = Arc::clone(&calls);
+        let first: ExecutePlanHook = Arc::new(move |_| {
+            *counted.lock().unwrap() += 1;
+            Err(SparkError::value_msg("the first hook"))
+        });
+        session.set_execute_plan_hook(Some(first));
+        session.set_execute_plan_hook(None);
+        let second: ExecutePlanHook = Arc::new(|_| 
Err(SparkError::value_msg("the second hook")));
+        session.set_execute_plan_hook(Some(second));
+        let error = session.range(1).unwrap().collect().unwrap_err();
+        assert!(error.to_string().contains("the second hook"), "{error}");
+        assert_eq!(*calls.lock().unwrap(), 0);
+    }
+}
diff --git a/crates/spark-connect/tests/execute_plan_hook.rs 
b/crates/spark-connect/tests/execute_plan_hook.rs
index 3748d231..0396a20a 100644
--- a/crates/spark-connect/tests/execute_plan_hook.rs
+++ b/crates/spark-connect/tests/execute_plan_hook.rs
@@ -17,21 +17,13 @@
 
 //! The hook of the executions of a session, as PySpark's 
`SparkSession.Hook.on_execute_plan`:
 //! called with each `ExecutePlanRequest` before it is sent, of whose request 
the execution is.
-//! The tests of a server run when SPARK_REMOTE is set.
+//! These tests run when SPARK_REMOTE is set; the ones without a server are in 
`session.rs`.
 
 use std::sync::{Arc, Mutex};
 
-use spark_connect::{ExecutePlanHook, SparkError, SparkSession};
+use spark_connect::{ExecutePlanHook, SparkSession};
 use spark_connect_proto as proto;
 
-fn offline() -> SparkSession {
-    // The channel connects lazily: the hook runs before a request is sent.
-    SparkSession::builder()
-        .remote("sc://127.0.0.1:1")
-        .get_or_create()
-        .unwrap()
-}
-
 fn live() -> Option<SparkSession> {
     let remote = std::env::var("SPARK_REMOTE").ok()?;
     Some(
@@ -42,43 +34,6 @@ fn live() -> Option<SparkSession> {
     )
 }
 
-#[test]
-fn the_error_of_a_hook_is_the_error_of_the_execution() {
-    let session = offline();
-    let seen: Arc<Mutex<Vec<proto::ExecutePlanRequest>>> = Arc::default();
-    let requests = Arc::clone(&seen);
-    let hook: ExecutePlanHook = Arc::new(move |request| {
-        requests.lock().unwrap().push(request);
-        Err(SparkError::value_msg("the hook failed"))
-    });
-    session.set_execute_plan_hook(Some(hook));
-    let error = session.range(3).unwrap().collect().unwrap_err();
-    assert!(error.to_string().contains("the hook failed"), "{error}");
-    let seen = seen.lock().unwrap();
-    assert_eq!(seen.len(), 1);
-    assert_eq!(seen[0].session_id, session.session_id());
-    assert!(seen[0].operation_id.is_some());
-    assert!(seen[0].plan.is_some());
-}
-
-#[test]
-fn a_cleared_or_replaced_hook_is_not_called() {
-    let session = offline();
-    let calls = Arc::new(Mutex::new(0));
-    let counted = Arc::clone(&calls);
-    let first: ExecutePlanHook = Arc::new(move |_| {
-        *counted.lock().unwrap() += 1;
-        Err(SparkError::value_msg("the first hook"))
-    });
-    session.set_execute_plan_hook(Some(first));
-    session.set_execute_plan_hook(None);
-    let second: ExecutePlanHook = Arc::new(|_| Err(SparkError::value_msg("the 
second hook")));
-    session.set_execute_plan_hook(Some(second));
-    let error = session.range(1).unwrap().collect().unwrap_err();
-    assert!(error.to_string().contains("the second hook"), "{error}");
-    assert_eq!(*calls.lock().unwrap(), 0);
-}
-
 #[test]
 fn the_request_of_a_hook_is_sent_with_the_operation_id_of_the_original() {
     let Some(session) = live() else {


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

Reply via email to