Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ foreign-types-shared: 0.1.1, "Apache-2.0 OR MIT",
form_urlencoded: 1.2.2, "Apache-2.0 OR MIT",
fragile: 2.0.1, "Apache-2.0",
fs-err: 3.2.2, "Apache-2.0 OR MIT",
fs2: 0.4.3, "Apache-2.0 OR MIT",
fs_extra: 1.3.0, "MIT",
fsevent-sys: 4.1.0, "MIT",
funty: 2.0.0, "MIT",
Expand Down Expand Up @@ -661,6 +662,7 @@ rmcp-macros: 0.14.0, "Apache-2.0",
rmp: 0.8.15, "MIT",
rmp-serde: 1.3.1, "MIT",
roaring: 0.11.3, "Apache-2.0 OR MIT",
rolling-file: 0.2.0, "Apache-2.0 OR MIT",
route-recognizer: 0.3.1, "MIT",
rsa: 0.9.10, "Apache-2.0 OR MIT",
rust-embed: 8.11.0, "MIT",
Expand Down
7 changes: 7 additions & 0 deletions core/common/src/utils/byte_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ impl IggyByteSize {
format!("{:.2}", self.0.get_appropriate_unit(UnitType::Decimal))
}

/// Subtract another IggyByteSize value, return 0 if the result is negative.
pub fn saturating_sub(&self, other: &Self) -> Self {
let self_bytes = self.as_bytes_u64();
let other_bytes = other.as_bytes_u64();
IggyByteSize::new(self_bytes.saturating_sub(other_bytes))
}

/// Calculates the throughput based on the provided duration and returns a human-readable string.
pub(crate) fn _as_human_throughput_string(&self, duration: &IggyDuration) -> String {
if duration.is_zero() {
Expand Down
29 changes: 29 additions & 0 deletions core/common/src/utils/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ use std::{

pub const SEC_IN_MICRO: u64 = 1_000_000;

/// A struct for representing time durations with various utility functions.
///
/// This struct wraps `std::time::Duration` and uses the `humantime` crate for parsing and formatting
/// human-readable duration strings. It also implements serialization and deserialization via the `serde` crate.
///
/// # Example
///
/// ```
/// use iggy_common::IggyDuration;
/// use std::str::FromStr;
///
/// let duration = IggyDuration::from(3661_000_000_u64); // 3661 seconds in microseconds
/// assert_eq!(3661, duration.as_secs());
/// assert_eq!("1h 1m 1s", duration.as_human_time_string());
/// assert_eq!("1h 1m 1s", format!("{}", duration));
///
/// let duration = IggyDuration::from(0_u64);
/// assert_eq!(0, duration.as_secs());
/// assert_eq!("0s", duration.as_human_time_string());
/// assert_eq!("0s", format!("{}", duration));
///
/// let duration = IggyDuration::from_str("1h 1m 1s").unwrap();
/// assert_eq!(3661, duration.as_secs());
/// assert_eq!("1h 1m 1s", duration.as_human_time_string());
/// assert_eq!("1h 1m 1s", format!("{}", duration));
///
/// let duration = IggyDuration::from_str("unlimited").unwrap();
/// assert_eq!(0, duration.as_secs());
/// ```
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct IggyDuration {
duration: Duration,
Expand Down
4 changes: 2 additions & 2 deletions core/integration/src/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl TestServer {
Ok(parallelism) => {
let available_cpus = parallelism.get();
if available_cpus >= 4 {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let max_start = available_cpus - 4;
let start = rng.gen_range(0..=max_start);
let start = rng.random_range(0..=max_start);
let end = start + 4;
format!("{}..{}", start, end)
} else {
Expand Down
Loading
Loading