Skip to content

test: replace tokio-current-thread alpha with tokio LocalSet#971

Closed
anikettuli wants to merge 1 commit intoStremio:developmentfrom
anikettuli:claude/remove-tokio-current-thread
Closed

test: replace tokio-current-thread alpha with tokio LocalSet#971
anikettuli wants to merge 1 commit intoStremio:developmentfrom
anikettuli:claude/remove-tokio-current-thread

Conversation

@anikettuli
Copy link
Copy Markdown

Summary

Replaces the deprecated tokio-current-thread = "=0.2.0-alpha.1" dev-dep with tokio::task::LocalSet from the stable tokio crate already in the workspace.

Why this change

tokio-current-thread is 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.1 carried forward because the test harness (src/unit_tests/env.rs) needed a single-threaded executor that could drain !Send futures 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 more tokio-executor, crossbeam-channel, crossbeam-utils, cfg-if pulled in transitively through this path).

Effect

  • One fewer abandoned dependency in the dev-dep graph.
  • Shrinks Cargo.lock by 4 transitive entries (~60 line removal).
  • No runtime behavior change in the published library; this is test infrastructure only. Test semantics (spawn-then-drain, two-phase state + event-loop separation) are preserved.
  • Unblocks modernizing the Env trait's concurrency docs to reference spawn_local directly.

Changes

src/unit_tests/env.rs

Two public helpers in the TestEnv harness:

  • TestEnv::run(runnable) — previously tokio_current_thread::block_on_all(future::lazy(|_| runnable())). Now builds a current-thread tokio runtime + LocalSet, runs the closure inside local.block_on, then drives the LocalSet to completion with rt.block_on(local). That last call preserves the key block_on_all semantic: spawned !Send futures finish before run returns.

  • TestEnv::run_with_runtime(rx, runtime, runnable) — originally two successive block_on_all calls. Now two successive LocalSet::block_on + rt.block_on(local) pairs named phase1 / 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 a LocalSet::block_on frame, which is the contract spawn_local expects.

Cargo.toml

  • Dropped tokio-current-thread = "=0.2.0-alpha.1" from [dev-dependencies]. The workspace's existing tokio = { version = "1.12", features = ["rt", "macros"] } already provides LocalSet and spawn_local.

Cargo.lock

Regenerated: removes tokio-current-thread, tokio-executor, crossbeam-channel, crossbeam-utils, and the cfg-if copy they pulled in.

Public API / contract

Zero changes to:

  • Storage keys (src/constants.rs:10)
  • WASM exports (stremio-core-web/src/stremio_core_web.rs:83-348)
  • Msg / Action / Event variants
  • Deep-link URL grammar
  • Serialized JSON field names

Test plan

Verified locally (Rust 1.85.1 stable-x86_64-pc-windows-gnu):

  • cargo test -p stremio-core --lib202 passed, 0 failed
  • cargo test -p stremio-watched-bitfield7 passed, 0 failed
  • cargo clippy --all --no-deps -- -D warnings — clean (the remaining future-incompat-report note is about wasm-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

`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
Copilot AI review requested due to automatic review settings April 20, 2026 05:03
@github-actions
Copy link
Copy Markdown

stremio-core-web prebuild

Prebuild artifact published by the Build workflow for branch claude/remove-tokio-current-thread.

Paste one of these into stremio-web's package.json and run pnpm install to wire this prebuild into a corresponding stremio-web PR:

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"

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_runtime to drive LocalSet on a current-thread Tokio runtime and drain spawned local tasks before returning.
  • Updated TestEnv’s Env implementation to use tokio::task::spawn_local instead of tokio_current_thread::spawn.
  • Removed tokio-current-thread from dev-dependencies and refreshed Cargo.lock accordingly.

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.

Comment thread src/unit_tests/env.rs
Comment on lines +72 to +75
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio runtime");
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/unit_tests/env.rs
Comment on lines +87 to +90
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio runtime");
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@anikettuli
Copy link
Copy Markdown
Author

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.

@anikettuli anikettuli closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants