-
Notifications
You must be signed in to change notification settings - Fork 66
feat: add loom concurrency testing with conditional sync primitives #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
kemingy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the loom to a dev target.
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
…ature Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Cargo.toml
Outdated
| [features] | ||
| loom = ["dep:loom"] | ||
|
|
||
| [dependencies.loom] | ||
| version = "0.7" | ||
| optional = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add loom to dev-dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved loom to dev-dependencies and switched to a feature-based approach instead of RUSTFLAGS to avoid dependency conflicts. The tests now work correctly with cargo test --features loom_tests loom_ (commit 703234d).
Makefile
Outdated
|
|
||
| test_loom: | ||
| echo "Running loom tests for concurrency validation" | ||
| cargo test --features loom loom_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RUSTFLAGS="--cfg loom"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use feature flags instead of RUSTFLAGS. Using --cfg loom globally caused compilation issues with dependencies like concurrent-queue. The new approach uses cargo test --features loom_tests loom_ which works correctly (commit 703234d).
src/tasks.rs
Outdated
| #[test] | ||
| fn loom_concurrent_notify_delete() { | ||
| loom::model(|| { | ||
| let task_manager = TaskManager::new(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should create a sync.rs file that contains both std and loom sync to be imported by TaskManager to use. Otherwise, this test doesn't add any benefit from loom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created sync.rs module with conditional compilation for std vs loom sync primitives. TaskManager now uses these conditional sync primitives, and the loom tests can properly model the synchronization behavior to detect concurrency issues (commit 703234d).
…alidation Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
…om tests Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
This PR adds loom testing to detect concurrency bugs like deadlocks and data races in the Rust codebase. The implementation uses a conditional sync primitives approach to enable loom testing without affecting normal builds.
Background
The implementation addresses deadlock bugs that occurred in:
Implementation
Conditional Sync Primitives: Created a
sync.rsmodule that conditionally exports eitherstd::syncorloom::syncprimitives based on feature flags. This allows the sameTaskManagercode to be tested under loom's concurrency model.Targeted Testing: The loom tests reproduce the exact mutex locking patterns from
TaskManagermethods likenotify_task_doneanddelete_taskthat caused the reported deadlocks.Usage
Tests Added
loom_concurrent_notify_delete: Tests the concurrent execution ofnotify_task_doneanddelete_taskoperations that mirror the problematic patterns from issues fix: resolve deadlock when lots of client requests closed before response #311 and fix: hold one lock at a time to avoid the deadlock in nested function #316loom_concurrent_table_access: Tests different mutex acquisition orders (table→notifiers vs notifiers→table) that can cause deadlocksThe tests successfully model the synchronization behavior and can detect the types of concurrency issues that occurred in production.
Fixes #317.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.