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
@@ -612,7 +612,7 @@ mod tests {
|
||||
|
||||
#[gpui::test(iterations = 100)]
|
||||
fn test_random_chunks(mut rng: StdRng) {
|
||||
let chunk_len = rng.gen_range(0..=MAX_BASE);
|
||||
let chunk_len = rng.random_range(0..=MAX_BASE);
|
||||
let text = RandomCharIter::new(&mut rng)
|
||||
.take(chunk_len)
|
||||
.collect::<String>();
|
||||
@@ -627,8 +627,8 @@ mod tests {
|
||||
verify_chunk(chunk.as_slice(), text);
|
||||
|
||||
for _ in 0..10 {
|
||||
let mut start = rng.gen_range(0..=chunk.text.len());
|
||||
let mut end = rng.gen_range(start..=chunk.text.len());
|
||||
let mut start = rng.random_range(0..=chunk.text.len());
|
||||
let mut end = rng.random_range(start..=chunk.text.len());
|
||||
while !chunk.text.is_char_boundary(start) {
|
||||
start -= 1;
|
||||
}
|
||||
@@ -645,7 +645,7 @@ mod tests {
|
||||
|
||||
#[gpui::test(iterations = 1000)]
|
||||
fn test_nth_set_bit_random(mut rng: StdRng) {
|
||||
let set_count = rng.gen_range(0..=128);
|
||||
let set_count = rng.random_range(0..=128);
|
||||
let mut set_bits = (0..128).choose_multiple(&mut rng, set_count);
|
||||
set_bits.sort();
|
||||
let mut n = 0;
|
||||
|
||||
+11
-11
@@ -1610,9 +1610,9 @@ mod tests {
|
||||
let mut expected = String::new();
|
||||
let mut actual = Rope::new();
|
||||
for _ in 0..operations {
|
||||
let end_ix = clip_offset(&expected, rng.gen_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.gen_range(0..=end_ix), Left);
|
||||
let len = rng.gen_range(0..=64);
|
||||
let end_ix = clip_offset(&expected, rng.random_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.random_range(0..=end_ix), Left);
|
||||
let len = rng.random_range(0..=64);
|
||||
let new_text: String = RandomCharIter::new(&mut rng).take(len).collect();
|
||||
|
||||
let mut new_actual = Rope::new();
|
||||
@@ -1629,8 +1629,8 @@ mod tests {
|
||||
log::info!("text: {:?}", expected);
|
||||
|
||||
for _ in 0..5 {
|
||||
let end_ix = clip_offset(&expected, rng.gen_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.gen_range(0..=end_ix), Left);
|
||||
let end_ix = clip_offset(&expected, rng.random_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.random_range(0..=end_ix), Left);
|
||||
|
||||
let actual_text = actual.chunks_in_range(start_ix..end_ix).collect::<String>();
|
||||
assert_eq!(actual_text, &expected[start_ix..end_ix]);
|
||||
@@ -1695,14 +1695,14 @@ mod tests {
|
||||
);
|
||||
|
||||
// Check that next_line/prev_line work correctly from random positions
|
||||
let mut offset = rng.gen_range(start_ix..=end_ix);
|
||||
let mut offset = rng.random_range(start_ix..=end_ix);
|
||||
while !expected.is_char_boundary(offset) {
|
||||
offset -= 1;
|
||||
}
|
||||
chunks.seek(offset);
|
||||
|
||||
for _ in 0..5 {
|
||||
if rng.r#gen() {
|
||||
if rng.random() {
|
||||
let expected_next_line_start = expected[offset..end_ix]
|
||||
.find('\n')
|
||||
.map(|newline_ix| offset + newline_ix + 1);
|
||||
@@ -1791,8 +1791,8 @@ mod tests {
|
||||
}
|
||||
|
||||
assert!((start_ix..=end_ix).contains(&chunks.offset()));
|
||||
if rng.r#gen() {
|
||||
offset = rng.gen_range(start_ix..=end_ix);
|
||||
if rng.random() {
|
||||
offset = rng.random_range(start_ix..=end_ix);
|
||||
while !expected.is_char_boundary(offset) {
|
||||
offset -= 1;
|
||||
}
|
||||
@@ -1876,8 +1876,8 @@ mod tests {
|
||||
}
|
||||
|
||||
for _ in 0..5 {
|
||||
let end_ix = clip_offset(&expected, rng.gen_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.gen_range(0..=end_ix), Left);
|
||||
let end_ix = clip_offset(&expected, rng.random_range(0..=expected.len()), Right);
|
||||
let start_ix = clip_offset(&expected, rng.random_range(0..=end_ix), Left);
|
||||
assert_eq!(
|
||||
actual.cursor(start_ix).summary::<TextSummary>(end_ix),
|
||||
TextSummary::from(&expected[start_ix..end_ix])
|
||||
|
||||
Reference in New Issue
Block a user