Extract a scheduler crate from GPUI to enable unified integration testing of client and server code (#37326)
Extracts and cleans up GPUI's scheduler code into a new `scheduler` crate, making it pluggable by external runtimes. This will enable deterministic integration testing with cloud components by providing a unified test scheduler across Zed and backend code. In Zed, it will replace the existing GPUI scheduler for consistent async task management across platforms. ## Changes - **Core Implementation**: `TestScheduler` with seed-based randomization, session tracking (`SessionId`), and foreground/background task separation for reproducible testing. - **Executors**: `ForegroundExecutor` (!Send, thread-local) and `BackgroundExecutor` (Send, with blocking/timeout support) as GPUI-compatible wrappers. - **Clock and Timer**: Controllable `TestClock` and future-based `Timer` for time-sensitive tests. - **Testing APIs**: `once()`, `with_seed()`, and `many()` methods for configurable test runs. - **Dependencies**: Added `async-task`, `chrono`, `futures`, etc., with updates to `Cargo.toml` and lock file. ## Benefits - **Integration Testing**: Facilitates reliable async tests involving cloud sessions, reducing flakiness via deterministic execution. - **Pluggability**: Trait-based design (`Scheduler`) allows easy integration into non-GPUI runtimes while maintaining GPUI compatibility. - **Cleanup**: Refactors GPUI scheduler logic for clarity, correctness (no `unwrap()`, proper error handling), and extensibility. Follows Rust guidelines; run `./script/clippy` for verification. - [x] Define and test a core scheduler that we think can power our cloud code and GPUI - [ ] Replace GPUI's scheduler Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
co-authored by
Antonio Scandurra
parent
a05f86f97b
commit
1ae326432e
@@ -3761,7 +3761,7 @@ impl LspStore {
|
||||
worktree_store,
|
||||
languages: languages.clone(),
|
||||
language_server_statuses: Default::default(),
|
||||
nonce: StdRng::from_entropy().r#gen(),
|
||||
nonce: StdRng::from_os_rng().random(),
|
||||
diagnostic_summaries: HashMap::default(),
|
||||
lsp_server_capabilities: HashMap::default(),
|
||||
lsp_document_colors: HashMap::default(),
|
||||
@@ -3823,7 +3823,7 @@ impl LspStore {
|
||||
worktree_store,
|
||||
languages: languages.clone(),
|
||||
language_server_statuses: Default::default(),
|
||||
nonce: StdRng::from_entropy().r#gen(),
|
||||
nonce: StdRng::from_os_rng().random(),
|
||||
diagnostic_summaries: HashMap::default(),
|
||||
lsp_server_capabilities: HashMap::default(),
|
||||
lsp_document_colors: HashMap::default(),
|
||||
|
||||
@@ -7661,7 +7661,7 @@ async fn test_staging_random_hunks(
|
||||
.unwrap_or(20);
|
||||
|
||||
// Try to induce races between diff recalculation and index writes.
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
executor.deprioritize(*CALCULATE_DIFF_TASK);
|
||||
}
|
||||
|
||||
@@ -7717,7 +7717,7 @@ async fn test_staging_random_hunks(
|
||||
assert_eq!(hunks.len(), 6);
|
||||
|
||||
for _i in 0..operations {
|
||||
let hunk_ix = rng.gen_range(0..hunks.len());
|
||||
let hunk_ix = rng.random_range(0..hunks.len());
|
||||
let hunk = &mut hunks[hunk_ix];
|
||||
let row = hunk.range.start.row;
|
||||
|
||||
@@ -7735,7 +7735,7 @@ async fn test_staging_random_hunks(
|
||||
hunk.secondary_status = SecondaryHunkAdditionPending;
|
||||
}
|
||||
|
||||
for _ in 0..rng.gen_range(0..10) {
|
||||
for _ in 0..rng.random_range(0..10) {
|
||||
log::info!("yielding");
|
||||
cx.executor().simulate_random_delay().await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user