type-c-service: Create integration test framework and migrate external example to test#881
Conversation
f9abb4e to
fa808ef
Compare
fa808ef to
8080d5e
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces an integration-test framework for type-c-service, including a mock Type‑C controller implementation and an initial test that exercises the “external” call surface end-to-end against the service/wrapper. To support assertions in the new tests, several Type‑C controller data types in embedded-services are updated to derive PartialEq/Eq. The PR also adjusts dev-dependencies to enable running these Tokio-based integration tests with logging.
Changes:
- Add a reusable integration-test harness (
tests/common/*) with mocked controllers and service task orchestration. - Add an integration test (
tests/external.rs) that validates many external-facing Type‑C operations by asserting both returned values and underlying controller function calls. - Update
embedded-servicesType‑C controller types to derivePartialEq/Eqfor test assertions; adjust workspace/crate dependencies for the new test setup.
Step-by-step review guide (grouped by concept)
-
New integration-test harness
- Review
type-c-service/tests/common/mod.rsfor how tasks are spawned (type-c-service,power-policy-service, and per-controller wrapper tasks), how shutdown is signaled, and how event channels are wired into the global registries. - Pay special attention to ordering: controller registration vs. when the test body starts issuing commands.
- Review
-
Mock controller behavior + observability
- Review
type-c-service/tests/common/mock.rsfor the contract it establishes:- queued “next result” FIFOs that drive the controller methods
- a
fn_callsqueue used by tests to assert which controller methods were invoked (and with which arguments)
- Review
-
External-call integration test
- Review
type-c-service/tests/external.rsfor API coverage and what is being asserted:- return values from
external::*calls - side effects (recorded
FnCalls) on the underlying mocked controller
- return values from
- Review
-
Controller type derivations to support equality assertions
- Review
embedded-service/src/type_c/controller.rsderive changes (PartialEq/Eq) to ensure they’re appropriate for these data types and don’t create unintended API constraints.
- Review
Potential issues
| # | Severity | File | Description | Code |
|---|---|---|---|---|
| 1 | High | type-c-service/tests/external.rs:10-20 |
The test imports/calls embedded_services::type_c::external::*, but this PR deletes embedded-service/src/type_c/external.rs; as-is, the test and embedded-services will not build unless external was moved/re-exported elsewhere in the PR. |
use embedded_services::{ ... type_c::{ ... external, }, }; |
| 2 | High | type-c-service/tests/common/mod.rs:57-62 |
Controller registration happens inside controller_task, but the test body is started concurrently via join3, creating a race where the test can issue commands before controllers are registered (flaky/non-deterministic tests). |
wrapper.register().await.unwrap(); (inside controller_task) |
| 3 | High | type-c-service/tests/common/mod.rs:1 and type-c-service/tests/common/mock.rs:1 |
Workspace clippy lints deny panic, unwrap_used, and expect_used, but the new test framework uses all three without #[allow(...)]; CI runs cargo clippy --tests, so this will fail. |
#![allow(dead_code)] (missing #![allow(clippy::...)]) |
| 4 | Medium | type-c-service/tests/common/mod.rs:147-157 |
The harness initializes multiple StaticCells on every run_test call; StaticCell::init is single-use, so run_test is not re-entrant despite adding a global mutex to run tests sequentially. |
static COMPLETION_SIGNAL: StaticCell<...> = StaticCell::new(); let completion_signal = COMPLETION_SIGNAL.init(...) |
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
type-c-service/tests/external.rs |
Adds an integration test that exercises Type‑C external-facing operations and asserts controller call traces. |
type-c-service/tests/common/mod.rs |
Adds a Tokio/Embassy-based test harness to run the Type‑C service, power policy, and mock controller wrappers concurrently. |
type-c-service/tests/common/mock.rs |
Implements a mock Type‑C controller with queued results and call recording to validate service behavior. |
type-c-service/Cargo.toml |
Updates dev-dependencies for the new integration tests (Tokio/logging/framework support). |
embedded-service/src/type_c/external.rs |
Deletes the existing external command API module (must be reconciled with new tests/imports). |
embedded-service/src/type_c/controller.rs |
Adds PartialEq/Eq derives to several controller-related types to enable equality assertions in tests. |
Cargo.toml |
Adds power-policy-service to workspace dependencies (used by the integration test crate dev-deps). |
Cargo.lock |
Updates lockfile for newly introduced dev-dependencies. |
17f1d36 to
dc54ba5
Compare
dc54ba5 to
10a5f0a
Compare
| pub mod mock; | ||
| pub const DEFAULT_TEST_DURATION: Duration = Duration::from_secs(5); | ||
|
|
||
| pub const DEFAULT_PER_CALL_TIMEOUT: Duration = Duration::from_secs(1); |
There was a problem hiding this comment.
nit: does this get used anywhere?
No description provided.