Skip to content

Conversation

@gurry
Copy link
Contributor

@gurry gurry commented Oct 21, 2025

This PR improves the performance of cargo-wdk integration tests by making the locks they take more fine grained. On my laptop the test execution time has reduced from ~13 minutes to ~5 minutes.

We need locks here for two reasons:

  1. To prevent a race while generating the cert from the cert store
  2. To avoid concurrently running multiple cargo build commands on the same driver project

Earlier we used a single lock to fulfil these requirements. That serialized all the tests with respect to each other and hurt performance. In this PR we still use locks but we do it differently.

To address requirement 1. we have made cargo-wdk itself take a lock on the cert store instead of relying on the test for synchronization. This lock is super fine-grained compared to before. For 2. we take a separate lock per driver project instead of having every test block on the same lock. Together these changes allow parallelism that improves performance.

Another thing: we now use a named mutex as the locking primitive instead of a file lock because mutexes are cleaner as they create no files. This also fixes #489.

While the performance wins here are significant, more can be done in this area. For example we could copy test projects out into their own isolated directories and run tests on those copies. That will eliminate requirement 2 entirely and remove all locks from the cargo-wdk test code giving us even bigger wins. Something to look into in the future.

Copilot AI review requested due to automatic review settings October 21, 2025 06:04
Copy link
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 refactors the cargo-wdk integration test suite to significantly improve performance by replacing coarse-grained file-based locking with fine-grained Windows named mutexes. The test execution time is reduced from ~24 minutes to ~10 minutes by:

  • Moving certificate store synchronization into cargo-wdk itself using a dedicated named mutex
  • Using per-project mutexes instead of a single global lock for build operations
  • Replacing file locks with Windows API named mutexes to avoid file system artifacts

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/cargo-wdk/tests/test_utils/mod.rs Implements NamedMutex wrapper and replaces with_file_lock with with_mutex helper function
crates/cargo-wdk/tests/new_command_test.rs Removes unnecessary lock acquisition from test command invocation
crates/cargo-wdk/tests/build_command_test.rs Replaces global locks with per-project mutex locks in build tests
crates/cargo-wdk/src/actions/build/tests.rs Removes .once() constraint to allow multiple mock invocations during parallel testing
crates/cargo-wdk/src/actions/build/package_task.rs Adds certificate store mutex to prevent race conditions when generating certificates
crates/cargo-wdk/Cargo.toml Adds windows crate dependency with required Win32 API features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 21, 2025 07:13
@gurry gurry force-pushed the making-cargo-wdk-tests-faster branch from ed8a5a8 to 2ef4c2d Compare October 21, 2025 07:13
Copy link
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

Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 21, 2025 07:39
Copy link
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

Copilot reviewed 7 out of 9 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 21, 2025 08:20
Copy link
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

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

/// An RAII wrapper over a Win API named mutex
pub struct NamedMutex {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately NamedMutex is duplicated because we don't have a common crate to put it in.

@gurry gurry marked this pull request as ready for review October 21, 2025 10:13
Copilot AI review requested due to automatic review settings October 21, 2025 10:13
@gurry gurry enabled auto-merge October 21, 2025 10:13
@gurry gurry requested a review from a team October 21, 2025 10:14
Copy link
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

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// create a cert in the store. It is not a correctness problem. We
// just don't want to litter the store with certs especially during
// tests when there are lots of parallel runs
let mutex_name = CString::new("WDRCertStoreMutex_bd345cf9330") // Unique enough
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this name to a constant and use it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used at only one place so didn't feel the need to do that

Copy link
Contributor

Choose a reason for hiding this comment

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

If not for reusability, can we consider doing it for consistency, so that all constants are defined in one place?

_not_send: PhantomData<*const ()>,
}

impl NamedMutex {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add unit tests for this custom Mutex implementation.

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.

Fix source tree pollution due to cargo-wdk-test.lock file created as part of cargo-wdk integration tests

2 participants