Skip to content

Commit

Permalink
use one from tokio-util
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Jan 14, 2025
1 parent ea9f624 commit 140e3bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sqllogictest-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tokio = { version = "1", features = [
"fs",
"process",
] }
tokio-util = { version = "0.7.12", features = ["rt"] }
fs-err = "3.0.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = "0.1"
29 changes: 2 additions & 27 deletions sqllogictest-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sqllogictest::{
default_column_validator, default_normalizer, default_validator, update_record_with_output,
AsyncDB, Injected, MakeConnection, Record, Runner,
};
use utils::AbortOnDropHandle;
use tokio_util::task::AbortOnDropHandle;

#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
#[must_use]
Expand Down Expand Up @@ -323,7 +323,7 @@ async fn run_parallel(
let engine = engine.clone();
let labels = labels.to_vec();
async move {
let (buf, res) = AbortOnDropHandle(tokio::spawn(async move {
let (buf, res) = AbortOnDropHandle::new(tokio::spawn(async move {
let mut buf = vec![];
let res =
connect_and_run_test_file(&mut buf, filename, &engine, config, &labels)
Expand Down Expand Up @@ -835,28 +835,3 @@ async fn update_record<M: MakeConnection>(

Ok(())
}

mod utils {
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use tokio::task::{JoinError, JoinHandle};

/// A wrapper around a [`tokio::task::JoinHandle`], which aborts the task when it is dropped.
pub struct AbortOnDropHandle<T>(pub JoinHandle<T>);

impl<T> Drop for AbortOnDropHandle<T> {
fn drop(&mut self) {
self.0.abort();
}
}

impl<T> Future for AbortOnDropHandle<T> {
type Output = Result<T, JoinError>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Pin::new(&mut self.0).poll(cx)
}
}
}

0 comments on commit 140e3bf

Please sign in to comment.