Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add field 'timeout' to TimeoutExecutor to specify the timeout and increase the timeout in the test case to 120 seconds #1033

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler_base/parallel/src/executor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ mod test_timeout_executor {
tasks.push(MyTask { id: i })
}

let executor = TimeoutExecutor::new_with_thread_count(thread_count);
let executor = TimeoutExecutor::new_with_thread_count_and_timeout(
thread_count,
Instant::now() + Duration::from_secs(120),
);

let mut events_collector = Arc::new(Mutex::new(EventsCollector::default()));

let expected_events =
Expand Down
21 changes: 20 additions & 1 deletion compiler_base/parallel/src/executor/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) struct TimeoutSituation {
pub struct TimeoutExecutor {
timeout_queue: VecDeque<TimeoutSituation>,
capacity: usize,
timeout: Option<Instant>,
}

impl TimeoutExecutor {
Expand All @@ -37,6 +38,20 @@ impl TimeoutExecutor {
TimeoutExecutor {
timeout_queue: VecDeque::default(),
capacity: thread_count,
timeout: Some(default_deadline_60_seconds()),
}
}

/// New a [`TimeoutExecutor`] with [`thread_count`] and [`timeout`].
pub fn new_with_thread_count_and_timeout(thread_count: usize, timeout: Instant) -> Self {
debug_assert!(
thread_count > 0,
"At least one thread is required to execute the task."
);
TimeoutExecutor {
timeout_queue: VecDeque::default(),
capacity: thread_count,
timeout: Some(timeout),
}
}

Expand Down Expand Up @@ -98,7 +113,11 @@ impl Executor for TimeoutExecutor {
let tinfo = task.info();

// Calculate the deadline.
let deadline = default_deadline_60_seconds();
let deadline = if let Some(timeout) = self.timeout {
timeout
} else {
default_deadline_60_seconds()
};

// Notify the log that the [`Task`] is waiting to be executed.
let event = TaskEvent::wait(task.info());
Expand Down
Loading