Skip to content

Commit

Permalink
Fix background task tests colliding
Browse files Browse the repository at this point in the history
We were creating multiple background tasks with the same progress text on multiple threads
  • Loading branch information
emesare committed Jan 18, 2025
1 parent fd9f230 commit 90e925a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions rust/tests/backgroundtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ fn session() -> Session {

#[rstest]
fn test_background_task_registered(_session: &Session) {
let task = BackgroundTask::new("test task", false);
let task_progress = "test registered";
let task = BackgroundTask::new(task_progress, false);
BackgroundTask::running_tasks()
.iter()
.find(|t| t.progress_text().as_str() == "test task")
.find(|t| t.progress_text().as_str() == task_progress)
.expect("Task not running");
task.finish();
let still_running = BackgroundTask::running_tasks()
.iter()
.find(|t| t.progress_text().as_str() == "test task")
.find(|t| t.progress_text().as_str() == task_progress)
.is_some();
assert!(!still_running, "Task still running");
}

#[rstest]
fn test_background_task_cancellable(_session: &Session) {
let task = BackgroundTask::new("test task", false);
let task_progress = "test cancellable";
let task = BackgroundTask::new(task_progress, false);
BackgroundTask::running_tasks()
.iter()
.find(|t| t.progress_text().as_str() == "test task")
.find(|t| t.progress_text().as_str() == task_progress)
.expect("Task not running");
task.cancel();
assert!(task.is_cancelled());
Expand All @@ -37,9 +39,9 @@ fn test_background_task_cancellable(_session: &Session) {

#[rstest]
fn test_background_task_progress(_session: &Session) {
let task = BackgroundTask::new("test task", false);
let task = BackgroundTask::new("test progress", false);
let first_progress = task.progress_text().to_string();
assert_eq!(first_progress, "test task");
assert_eq!(first_progress, "test progress");
task.set_progress_text("new progress");
let second_progress = task.progress_text().to_string();
assert_eq!(second_progress, "new progress");
Expand Down

0 comments on commit 90e925a

Please sign in to comment.