Skip to content

Commit

Permalink
Added unit test to test #5334 (#5341)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton authored Aug 23, 2024
1 parent d43f013 commit 7bed022
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion quickwit/quickwit-storage/src/split_cache/split_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,16 @@ pub(crate) struct DownloadOpportunity {
#[cfg(test)]
mod tests {
use std::num::NonZeroU32;
use std::sync::Arc;

use bytesize::ByteSize;
use quickwit_common::uri::Uri;
use quickwit_config::SplitCacheLimits;
use ulid::Ulid;

use crate::split_cache::split_table::{DownloadOpportunity, SplitTable};
use crate::split_cache::split_table::{
CandidateSplit, DownloadOpportunity, SplitInfo, SplitKey, SplitTable, Status,
};

const TEST_STORAGE_URI: &str = "s3://test";

Expand Down Expand Up @@ -667,4 +670,38 @@ mod tests {
);
}
}

// Unit test for #5334
#[test]
fn test_split_inserted_is_the_worst_candidate_5334() {
let mut split_table = SplitTable::with_limits_and_existing_splits(
SplitCacheLimits {
max_num_bytes: ByteSize::mb(10),
max_num_splits: NonZeroU32::new(2).unwrap(),
num_concurrent_downloads: NonZeroU32::new(1).unwrap(),
max_file_descriptors: NonZeroU32::new(100).unwrap(),
},
Default::default(),
);
for i in (0u128..=super::MAX_NUM_CANDIDATES as u128).rev() {
let split_ulid = Ulid(i);
let candidate_split = CandidateSplit {
storage_uri: Uri::for_test(TEST_STORAGE_URI),
split_ulid,
living_token: Arc::new(()),
};
let split_info = SplitInfo {
split_key: SplitKey {
last_accessed: 0u64,
split_ulid,
},
status: Status::Candidate(candidate_split),
};
split_table.insert(split_info);
}
assert_eq!(
split_table.candidate_splits.len(),
super::MAX_NUM_CANDIDATES
);
}
}

0 comments on commit 7bed022

Please sign in to comment.