use super::*;
#[test]
fn holds_lock_reports_currently_held_rank() {
assert!(!holds_lock(LockRank::Layers));
assert!(!holds_lock(LockRank::Vectors));
record_lock_acquire(LockRank::Layers);
assert!(holds_lock(LockRank::Layers));
assert!(!holds_lock(LockRank::Vectors));
record_lock_release(LockRank::Layers);
assert!(!holds_lock(LockRank::Layers));
}
#[test]
fn gpu_vectors_snapshot_rank_sorts_before_vectors() {
assert!(LockRank::GpuVectorsSnapshot < LockRank::Vectors);
assert!(LockRank::Layers < LockRank::Neighbors);
}
#[test]
fn nested_acquire_in_declared_order_reports_both_held() {
record_lock_acquire(LockRank::GpuVectorsSnapshot);
record_lock_acquire(LockRank::Vectors);
assert!(holds_lock(LockRank::GpuVectorsSnapshot));
assert!(holds_lock(LockRank::Vectors));
record_lock_release(LockRank::Vectors);
record_lock_release(LockRank::GpuVectorsSnapshot);
assert!(!holds_lock(LockRank::GpuVectorsSnapshot));
assert!(!holds_lock(LockRank::Vectors));
}
#[test]
fn vectors_after_layers_counts_a_violation() {
let before = HNSW_COUNTERS.snapshot().invariant_violation_total;
record_lock_acquire(LockRank::Layers);
record_lock_acquire(LockRank::Vectors); record_lock_release(LockRank::Vectors);
record_lock_release(LockRank::Layers);
assert!(HNSW_COUNTERS.snapshot().invariant_violation_total > before,);
}