test: replace tokio-current-thread alpha with tokio LocalSet#971
test: replace tokio-current-thread alpha with tokio LocalSet#971anikettuli wants to merge 1 commit intoStremio:developmentfrom
Conversation
`tokio-current-thread = "=0.2.0-alpha.1"` is a pre-1.0 tokio crate that has
been deprecated for years. It was still pinned to an alpha here because the
test harness (src/unit_tests/env.rs) relies on a single-threaded executor
that drains spawned `!Send` futures before returning.
Modern tokio provides the same capability via `tokio::task::LocalSet`:
- `tokio_current_thread::block_on_all(future)` replaced with a
`Builder::new_current_thread` runtime + two-phase `LocalSet` drives that
preserve the original two-step semantic of `run_with_runtime` (state
capture + runnable, then event loop + runtime close, each draining
spawn_local tasks between phases).
- `tokio_current_thread::spawn(future)` replaced with
`tokio::task::spawn_local(future)` in the `Env::exec_{concurrent,sequential}`
impls. Any call is still scoped inside a `LocalSet::block_on`, matching
the behavior the old spawn relied on.
No production code changes. No Env trait surface change. No behavior change
observable to the library's public API; test semantics (drain-between-phases)
are preserved.
Removed:
- `tokio-current-thread = "=0.2.0-alpha.1"` from `[dev-dependencies]`.
- Transitive dev deps no longer needed: `tokio-executor`, `crossbeam-channel`,
`crossbeam-utils`, `cfg-if` (removed by `cargo`, reflected in `Cargo.lock`).
Verified locally (Rust 1.85.1 stable-x86_64-pc-windows-gnu):
cargo test -p stremio-core --lib -> 202 passed, 0 failed
cargo clippy --all --no-deps -D warnings -> clean
cargo fmt --check -> clean
stremio-core-web prebuildPrebuild artifact published by the Paste one of these into Release "@stremio/stremio-core-web": "https://stremio.github.io/stremio-core/stremio-core-web/claude/remove-tokio-current-thread/stremio-stremio-core-web-0.56.3.tgz"Dev "@stremio/stremio-core-web": "https://stremio.github.io/stremio-core/stremio-core-web/claude/remove-tokio-current-thread/dev/stremio-stremio-core-web-0.56.3.tgz" |
There was a problem hiding this comment.
Pull request overview
Updates the test harness to use stable Tokio primitives by replacing the deprecated tokio-current-thread dev-dependency with tokio::task::LocalSet on a current-thread runtime, while preserving the “spawn then drain before returning” behavior needed for !Send futures.
Changes:
- Reworked
TestEnv::run/TestEnv::run_with_runtimeto driveLocalSeton a current-thread Tokio runtime and drain spawned local tasks before returning. - Updated
TestEnv’sEnvimplementation to usetokio::task::spawn_localinstead oftokio_current_thread::spawn. - Removed
tokio-current-threadfrom dev-dependencies and refreshedCargo.lockaccordingly.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/unit_tests/env.rs | Migrates test executor plumbing to tokio::runtime::Builder::new_current_thread + LocalSet and switches task spawning to spawn_local. |
| Cargo.toml | Drops deprecated tokio-current-thread from [dev-dependencies]. |
| Cargo.lock | Removes tokio-current-thread and related transitive deps from the lockfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let rt = tokio::runtime::Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .expect("tokio runtime"); |
There was a problem hiding this comment.
tokio::runtime::Builder::new_current_thread()...build() is duplicated in both run and run_with_runtime. Consider extracting a small helper (e.g., fn new_test_runtime() -> Runtime) to keep the harness DRY and make future runtime configuration changes less error-prone.
| let rt = tokio::runtime::Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .expect("tokio runtime"); |
There was a problem hiding this comment.
The expect("tokio runtime") message is fairly generic; if runtime construction fails it will be hard to diagnose from test logs. Consider using a more specific message (e.g., indicate current-thread runtime build failure).
|
Superseded by #973 — the five dead-weight/MSRV modernizations are bundled there to avoid five near-identical Cargo.toml / Cargo.lock merges. Each change remains a distinct commit for piecewise review. |
Summary
Replaces the deprecated
tokio-current-thread = "=0.2.0-alpha.1"dev-dep withtokio::task::LocalSetfrom the stabletokiocrate already in the workspace.Why this change
tokio-current-threadis a pre-1.0 tokio crate — its final release is an alpha from 2018. It has been effectively abandoned for ~8 years, yet the pin=0.2.0-alpha.1carried forward because the test harness (src/unit_tests/env.rs) needed a single-threaded executor that could drain!Sendfutures before returning.Modern tokio provides exactly that capability via
tokio::task::LocalSet. Migrating removes a zombie dep, keeps the toolchain on supported crates, and shrinks the transitive dev-dep graph (no moretokio-executor,crossbeam-channel,crossbeam-utils,cfg-ifpulled in transitively through this path).Effect
Cargo.lockby 4 transitive entries (~60 line removal).spawn_localdirectly.Changes
src/unit_tests/env.rsTwo public helpers in the
TestEnvharness:TestEnv::run(runnable)— previouslytokio_current_thread::block_on_all(future::lazy(|_| runnable())). Now builds a current-thread tokio runtime +LocalSet, runs the closure insidelocal.block_on, then drives theLocalSetto completion withrt.block_on(local). That last call preserves the keyblock_on_allsemantic: spawned!Sendfutures finish beforerunreturns.TestEnv::run_with_runtime(rx, runtime, runnable)— originally two successiveblock_on_allcalls. Now two successiveLocalSet::block_on+rt.block_on(local)pairs namedphase1/phase2, preserving the original contract that Phase 1 (state capture + runnable + any effects it spawns) drains fully before Phase 2 (event collection + runtime close) starts.Env impl:
exec_concurrent/exec_sequential:tokio_current_thread::spawn(future)→tokio::task::spawn_local(future). Every call site is (still) reached from within aLocalSet::block_onframe, which is the contractspawn_localexpects.Cargo.tomltokio-current-thread = "=0.2.0-alpha.1"from[dev-dependencies]. The workspace's existingtokio = { version = "1.12", features = ["rt", "macros"] }already providesLocalSetandspawn_local.Cargo.lockRegenerated: removes
tokio-current-thread,tokio-executor,crossbeam-channel,crossbeam-utils, and thecfg-ifcopy they pulled in.Public API / contract
Zero changes to:
src/constants.rs:10)stremio-core-web/src/stremio_core_web.rs:83-348)Msg/Action/EventvariantsTest plan
Verified locally (Rust 1.85.1
stable-x86_64-pc-windows-gnu):cargo test -p stremio-core --lib— 202 passed, 0 failedcargo test -p stremio-watched-bitfield— 7 passed, 0 failedcargo clippy --all --no-deps -- -D warnings— clean (the remainingfuture-incompat-reportnote is aboutwasm-bindgen 0.2.78; that's what build: upgrade wasm-bindgen 0.2.78 → 0.2.118 and WASM deps #969 upgrades)cargo fmt --check— clean