Skip to content

Commit

Permalink
feat: add field 'timeout' to TimeoutExecutor to specify the timeout a…
Browse files Browse the repository at this point in the history
…nd increase the timeout in the test case to 120 seconds

Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Feb 6, 2024
1 parent 7232ff1 commit fed2e83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit fed2e83

Please sign in to comment.