Root cause of the failing CI run was that examples/tests referencing feature-gated items were auto-detected (no required-features), so `--all-targets` compiled them under feature combinations where those modules didn't exist. Fixes: - mytheclipse Cargo.toml: declare the `high_level` example and `race_stress` integration test with required-features = ["full"]; `cargo build --all-targets` now skips them when full is off. This clears the whole test-matrix (workspace default, all-features, and every single-feature config) which all failed on E0432/E0433. - lib.rs: auto_metrics_service depends on service_builder, so regate it behind all(observability, resiliency) instead of observability alone (observability-only build compiled the module without resiliency). - mytheclipse-tracing: gate `pub mod fmt` behind any tracing-subscriber-providing feature so --no-default-features compiles. - mytheclipse-queue: gate `pub mod worker` behind in-memory (worker.rs requires tokio, only provided by in-memory). - clippy -D warnings fixes: deprecated base64 0.22 free fns -> Engine (paseto), unused key field, needless mut (service_builder), unused import/dead var/missing is_empty (bg_join), dead is_expired (dlock), while-let-iterator->for (parallel_map), type_complexity (shutdown_guard), MutexGuard held across await (middleware, now clones Arc'd layers), if-let-Err->is_err (queue), unused CliBuilder fields now wired into clap. - rustdoc -D warnings: resolve retry/MetricsBridge/CircuitBreaker/KeyRing intra-doc links and fix the unparseable lifecycle.rs code fence. - cargo fmt --all to satisfy the Rustfmt gate.
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
//! Race-safety stress tests for the queue crate's rate-limited primitives.
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
use mytheclipse_queue::in_memory::InMemoryQueue;
|
|
use mytheclipse_queue::rate_limited::RateLimitedQueue;
|
|
use mytheclipse_queue::traits::Queue;
|
|
|
|
const TASKS: usize = 8;
|
|
const PER_TASK: usize = 1000;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn rate_limited_queue_no_item_loss_under_contention() {
|
|
// Enqueue 8000 items, dequeue them all concurrently: nothing may vanish.
|
|
let inner = InMemoryQueue::new();
|
|
let q = Arc::new(RateLimitedQueue::new(inner, 1_000_000.0, 10_000));
|
|
|
|
let producer: tokio::task::JoinHandle<()> = tokio::spawn({
|
|
let q = Arc::clone(&q);
|
|
async move {
|
|
for i in 0..(TASKS * PER_TASK) {
|
|
q.enqueue("stress", format!("item-{i}").into_bytes())
|
|
.await
|
|
.unwrap();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Drain concurrently with the producer.
|
|
let seen = Arc::new(AtomicUsize::new(0));
|
|
let mut workers = Vec::new();
|
|
for _ in 0..TASKS {
|
|
let q = Arc::clone(&q);
|
|
let s = Arc::clone(&seen);
|
|
workers.push(tokio::spawn(async move {
|
|
loop {
|
|
match q
|
|
.dequeue("stress", Duration::from_millis(50))
|
|
.await
|
|
.unwrap()
|
|
{
|
|
Some(job) => {
|
|
let _ = String::from_utf8(job.payload).unwrap();
|
|
s.fetch_add(1, Ordering::SeqCst);
|
|
}
|
|
None => {
|
|
// Empty + producer done => we're finished.
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
producer.await.unwrap();
|
|
for w in workers {
|
|
w.await.unwrap();
|
|
}
|
|
|
|
// Slight subtlety: a worker may observe None while producer still has
|
|
// items in flight (producer finished above, but enqueue is async —
|
|
// actually producer.await guarantees all enqueues completed). Since the
|
|
// producer finished, any None means truly drained.
|
|
assert_eq!(
|
|
seen.load(Ordering::SeqCst),
|
|
TASKS * PER_TASK,
|
|
"items lost under contention"
|
|
);
|
|
}
|