Skip to content

Commit

Permalink
Added unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coder137 committed Jul 22, 2024
1 parent c4a0b8f commit e717951
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/ticked_async_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,48 @@ mod tests {
let elapsed = now.elapsed();
println!("Elapsed: {:?}", elapsed);
println!("Total: {:?}", instances);

// Test Timer cancellation
let timer = executor.create_timer();
executor
.spawn("ThreadedFuture", async move {
timer.sleep_for(1000.0).await;
})
.detach();

let timer = executor.create_timer();
executor
.spawn_local("LocalFuture", async move {
timer.sleep_for(1000.0).await;
})
.detach();

let mut tick_event = executor.tick_channel();
executor
.spawn("ThreadedTickFuture", async move {
loop {
let _r = tick_event.changed().await;
if _r.is_err() {
break;
}
}
})
.detach();

let mut tick_event = executor.tick_channel();
executor
.spawn_local("LocalTickFuture", async move {
loop {
let _r = tick_event.changed().await;
if _r.is_err() {
break;
}
}
})
.detach();

executor.tick(DELTA);
assert_eq!(executor.num_tasks(), 4);
drop(executor);
}
}
2 changes: 2 additions & 0 deletions src/ticked_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ impl TickedTimer {
loop {
let _r = self.tick_recv.changed().await;
if _r.is_err() {
// This means that the executor supplying the delta channel has shutdown
// We must stop waiting gracefully
break;

Check warning on line 12 in src/ticked_timer.rs

View check run for this annotation

Codecov / codecov/patch

src/ticked_timer.rs#L12

Added line #L12 was not covered by tests
}
let current_dt = *self.tick_recv.borrow_and_update();
Expand Down

0 comments on commit e717951

Please sign in to comment.