-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple test #9
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "*" | ||
pull_request: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build_and_test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
toolchain: | ||
- stable | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Rustup | ||
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} | ||
- name: Install cargo-llvm-cov | ||
uses: taiki-e/install-action@cargo-llvm-cov | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Test | ||
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: lcov.info | ||
fail_ci_if_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use kv_extsort::{Result, SortConfig}; | ||
use log::{debug, error}; | ||
use rand::{rngs::SmallRng, Rng, SeedableRng}; | ||
use std::{convert::Infallible, time::Instant}; | ||
|
||
#[test] | ||
fn test_simple() -> Result<(), Infallible> { | ||
env_logger::init(); | ||
|
||
// Data source | ||
let size = 200_000; | ||
let make_iter = || { | ||
let body_size = 2046; | ||
|
||
let mut rng = SmallRng::from_entropy(); | ||
type T = (i32, Vec<u8>); | ||
let source = (0..size).map(move |_| { | ||
let u: i32 = rng.gen(); | ||
let s = vec![0; body_size]; | ||
(u, s) | ||
}); | ||
|
||
let head_size = std::mem::size_of::<T>(); | ||
let total_size = size * (head_size + body_size); | ||
debug!("Total size: {} MiB", total_size / 1024 / 1024); | ||
|
||
source | ||
}; | ||
|
||
let t = Instant::now(); | ||
let config = SortConfig::new() | ||
.max_chunk_bytes(2 * 1024 * 1024) | ||
.concurrency(num_cpus::get()) | ||
.merge_k(16); | ||
|
||
// Setup cancellation | ||
let canceled = config.get_cancel_flag(); | ||
ctrlc::set_handler(move || { | ||
canceled.store(true, std::sync::atomic::Ordering::Relaxed); | ||
}) | ||
.expect("Error setting Ctrl-C handler"); | ||
|
||
// Sort | ||
let mut prev_key = None; | ||
let mut count = 0; | ||
for res in kv_extsort::sort(make_iter().map(Result::<_, Infallible>::Ok), config) { | ||
match res { | ||
Ok((_key, _value)) => { | ||
// validate if sorted | ||
count += 1; | ||
if let Some(p) = prev_key { | ||
assert!(p <= _key); | ||
prev_key = Some(_key); | ||
} | ||
} | ||
Err(e) => { | ||
error!("{:?}", e); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
debug!("count: {count}"); | ||
assert!(count == size, "count: {} != size: {}", count, size); | ||
ciscorn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
debug!("Time elapsed: {:?}", t.elapsed()); | ||
|
||
Ok(()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ログの初期化が適切に行われていますが、テスト関数内で
env_logger::init();
を呼び出すことは一般的ではありません。テストの前に一度だけ初期化することをお勧めします。