//! Shared test helpers: a sleep wrapper and a call counter.
//!
//! Each test file pulls in this module but uses only the helpers it needs, so
//! some items look unused per file.
#![allow(dead_code)]

use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::Duration;

/// Sleep for `ms` milliseconds. Mirrors the sleep primitive the suite leans on.
pub async fn sleep(ms: u64) {
    tokio::time::sleep(Duration::from_millis(ms)).await;
}

/// A shared counter for tracking how many times the wrapped function ran.
#[derive(Clone, Default)]
pub struct Counter(Arc<AtomicUsize>);

impl Counter {
    /// A fresh counter starting at zero.
    pub fn new() -> Self {
        Counter::default()
    }

    /// Increment and return the value before the increment.
    pub fn bump(&self) -> usize {
        self.0.fetch_add(1, Ordering::SeqCst)
    }

    /// Read the current count.
    pub fn get(&self) -> usize {
        self.0.load(Ordering::SeqCst)
    }
}
