Skip to content

type-c-service: Create integration test framework and migrate external example to test#881

Open
RobertZ2011 wants to merge 4 commits into
OpenDevicePartnership:stable-v0.1.yfrom
RobertZ2011:type-c-integration-test-port
Open

type-c-service: Create integration test framework and migrate external example to test#881
RobertZ2011 wants to merge 4 commits into
OpenDevicePartnership:stable-v0.1.yfrom
RobertZ2011:type-c-integration-test-port

Conversation

@RobertZ2011
Copy link
Copy Markdown
Contributor

No description provided.

@RobertZ2011 RobertZ2011 self-assigned this Jun 4, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-integration-test-port branch from f9abb4e to fa808ef Compare June 5, 2026 18:52
@RobertZ2011 RobertZ2011 requested a review from Copilot June 5, 2026 18:53
@RobertZ2011 RobertZ2011 force-pushed the type-c-integration-test-port branch from fa808ef to 8080d5e Compare June 5, 2026 18:55
Copy link
Copy Markdown
Contributor

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

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-services Type‑C controller types to derive PartialEq/Eq for test assertions; adjust workspace/crate dependencies for the new test setup.

Step-by-step review guide (grouped by concept)

  1. New integration-test harness

    • Review type-c-service/tests/common/mod.rs for 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.
  2. Mock controller behavior + observability

    • Review type-c-service/tests/common/mock.rs for the contract it establishes:
      • queued “next result” FIFOs that drive the controller methods
      • a fn_calls queue used by tests to assert which controller methods were invoked (and with which arguments)
  3. External-call integration test

    • Review type-c-service/tests/external.rs for API coverage and what is being asserted:
      • return values from external::* calls
      • side effects (recorded FnCalls) on the underlying mocked controller
  4. Controller type derivations to support equality assertions

    • Review embedded-service/src/type_c/controller.rs derive changes (PartialEq/Eq) to ensure they’re appropriate for these data types and don’t create unintended API constraints.

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.

Comment thread type-c-service/tests/common/mod.rs
Comment thread type-c-service/tests/common/mock.rs
Comment thread type-c-service/tests/common/mod.rs
Comment thread type-c-service/tests/common/mod.rs
Comment thread type-c-service/tests/external.rs
@RobertZ2011 RobertZ2011 force-pushed the type-c-integration-test-port branch 2 times, most recently from 17f1d36 to dc54ba5 Compare June 5, 2026 21:39
@RobertZ2011 RobertZ2011 changed the title type-c-service: Create integration test framework type-c-service: Create integration test framework and migrate external example to test Jun 5, 2026
@RobertZ2011 RobertZ2011 marked this pull request as ready for review June 5, 2026 21:43
@RobertZ2011 RobertZ2011 requested review from a team as code owners June 5, 2026 21:43
@RobertZ2011 RobertZ2011 force-pushed the type-c-integration-test-port branch from dc54ba5 to 10a5f0a Compare June 5, 2026 23:34
pub mod mock;
pub const DEFAULT_TEST_DURATION: Duration = Duration::from_secs(5);

pub const DEFAULT_PER_CALL_TIMEOUT: Duration = Duration::from_secs(1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: does this get used anywhere?

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.

4 participants