Skip to content

Commit

Permalink
ci: Introduce code coverage check (#131)
Browse files Browse the repository at this point in the history
* introduce code coverage check

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
  • Loading branch information
Connor1996 authored Jun 7, 2022
1 parent c9f75b2 commit 72f57fb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target
key: ${{ runner.os }}-cargo-test
- uses: actions-rs/toolchain@v1
name: Setup Cargo Toolchain 🛎️
with:
components: rustfmt, clippy
components: rustfmt, clippy, llvm-tools-preview
toolchain: nightly
default: true
- name: Check Code Format 🔧
Expand All @@ -40,8 +44,14 @@ jobs:
git diff --quiet
- name: Linting The Code 🩹
run: make clippy
- name: Running Tests 🚀
run: make test
- uses: taiki-e/install-action@cargo-llvm-cov
- name: Running Tests With Code Coverage 🚀
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload Coverage To Codecov ⬆️
uses: codecov/codecov-action@v1
with:
files: lcov.info
fail_ci_if_error: true
sanitizer_test:
name: Test with Sanitizer
runs-on: ubuntu-latest
Expand All @@ -54,8 +64,12 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target
key: ${{ runner.os }}-${{ matrix.sanitizer }}-cargo-sanitizer-test
- uses: actions-rs/toolchain@v1
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

SANITIZER_FLAGS=-Zsanitizer=address

unset-override:
@# unset first in case of any previous overrides
@if rustup override list | grep `pwd` > /dev/null; then rustup override unset; fi

pre-format: unset-override
pre-format:
@rustup component add rustfmt
@cargo install -q cargo-sort

Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment:
layout: "diff"
behavior: default

coverage:
status:
project:
default:
target: auto
threshold: 3%
patch:
default:
target: auto
threshold: 3%
7 changes: 4 additions & 3 deletions src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl Core {

let mut out = vec![];

for table in this_level.tables.iter() {
for table in &this_level.tables {
if table.size() >= 2 * compact_def.targets.file_size[0] {
// File already big, don't include it.
continue;
Expand Down Expand Up @@ -668,7 +668,7 @@ impl Core {
} else {
let mut kr = KeyRange::default();
// Start from the oldest file first.
for table in this_level.tables.iter() {
for table in &this_level.tables {
let dkr = get_key_range_single(table);
if kr.overlaps_with(&dkr) {
out.push(table.clone());
Expand Down Expand Up @@ -928,7 +928,8 @@ impl Core {
if level < start_level {
continue;
}
match handler.read()?.get(key) {
let v = handler.read()?.get(key);
match v {
Ok(value) => {
if value.value.is_empty() && value.meta == 0 {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/levels/compaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ impl KeyRange {

/// Returns `true` if current key range is infinite
pub fn is_inf(&self) -> bool {
return matches!(self, KeyRange::Inf);
matches!(self, KeyRange::Inf)
}

/// Returns `true` if current key range is empty
pub fn is_empty(&self) -> bool {
return matches!(self, KeyRange::Empty);
matches!(self, KeyRange::Empty)
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/value_log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::{HashMap, HashSet},
iter::FromIterator,
path::{Path, PathBuf},
sync::{atomic::AtomicU32, Arc, RwLock},
};
Expand Down Expand Up @@ -153,20 +154,18 @@ impl ValueLog {
/// Gets sorted valid vlog files' ID set.
fn sorted_fids(&self) -> Vec<u32> {
let core = self.core.read().unwrap();
let mut to_be_deleted = HashSet::new();
for fid in &core.files_to_delete {
to_be_deleted.insert(*fid);
}
let mut result = vec![];
for fid in core.files_map.keys() {
if !to_be_deleted.contains(fid) {
result.push(*fid);
}
}
let to_be_deleted: HashSet<u32> = HashSet::from_iter(core.files_to_delete.iter().cloned());
let mut result = core
.files_map
.keys()
.into_iter()
.filter(|k| !to_be_deleted.contains(k))
.cloned()
.collect::<Vec<u32>>();
// Hold read lock as short as we can
drop(core);

// cargo clippy suggests using `sort_ubstable`
// cargo clippy suggests using `sort_unstable`
result.sort_unstable();
result
}
Expand Down

0 comments on commit 72f57fb

Please sign in to comment.