fix(db): 流式缓存测试脱离 GPUI 调度器以消除调度竞态 - #231
Merged
Merged
Conversation
execute_streaming_cancellable 通过 Tokio::spawn 把请求交给 Tokio 执行,并在 GPUI 后台执行器上等待其 JoinHandle。请求在 tokio worker 线程完成后会在该线程 唤醒这个 GPUI 后台任务,TestScheduler 将其判为 "Detected activity on thread tokio-rt-worker",并在 end_test 处报错。这 5 个流式 缓存测试因此依赖真实 Tokio 的完成时序,在 CI 全量并行下偶发失败。 改为 #[tokio::test],直接构造 StreamingExecutionRequest 在 Tokio runtime 上运行, 不再经过 GPUI 调度器;同时抽出 streaming_exec_opts 让生产路径与测试共用 options 归一化逻辑,避免测试镜像漂移。 验证: - cargo test -p db --lib:1301 passed / 0 failed - rustfmt --edition 2024 --check crates/db/src/manager.rs:clean - cargo clippy -p db --all-targets:无新增告警 - 变异验证:把 transactional + Error 分支的保守失效改回 false,该测试干净断言失败
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CI's
cargo test --alloccasionally failed within
db::manager::tests::failed_transactional_streaming_conservatively_invalidates_connection_cache(1300 passed; 1 failed).Root cause.
GlobalDbState::execute_streaming_cancellablehands the request to Tokio withTokio::spawn(cx, request.run()), andTokio::spawn(crates/core/src/gpui_tokio.rs) wraps that join handle incx.background_spawn(...). When the request completes on a tokio worker thread,Trailer::wake_joinwakes that GPUI background task from the worker thread, soTestScheduler::schedule_background_with_priorityobserves activity on a foreign thread, records it viaassert_correct_thread, andend_testpanics after the test body already succeeded. It is a load-dependent race: the test passes locally and only trips under the fully parallel CI run.Fix (test-side only — the production call path is unchanged). The five streaming cache tests are converted from
#[gpui::test]to#[tokio::test]and now buildStreamingExecutionRequestdirectly on a real Tokio runtime, mirroring what the production call path does, so they no longer touch the GPUI scheduler. This matches the existing repo lesson that spawned background work should be covered with a plain#[tokio::test], and the same pattern already used bycancelling_streaming_execution_drops_query_and_closes_sessionin this file.cx.executor().allow_parking()was considered and rejected: it would silence the determinism detector for the whole test instead of removing the dependency on the scheduler.Also extracted
streaming_exec_opts()so the production path and the tests share oneExecOptionsnormalization (file sources always stream) rather than duplicating it.Net effect: 99 insertions, 136 deletions in
crates/db/src/manager.rs.How to Test
cargo test -p db --lib→1301 passed; 0 failedrustfmt --edition 2024 --check crates/db/src/manager.rs→ cleancargo clippy -p db --all-targets→ exit 0, no new warnings (only pre-existingtoo_many_arguments/let_underscore_futureitems inmanager.rs)StreamingExecutionOutcome::Error => had_successful_progresstofalseinsideshould_conservatively_invalidate_streamingmakes the converted test fail with a clean assertion error (a failed transaction after successful progress has an ambiguous final state), confirming the rewritten tests still cover the invalidation semantics.Checklist
cargo runfor story tests related to the changes.