feat: add loom concurrency testing with conditional sync primitives#658
feat: add loom concurrency testing with conditional sync primitives#658
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.
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.
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.
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.
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.
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.