Skip to content

Commit

Permalink
Merge branch 'main' into development
Browse files Browse the repository at this point in the history
* main:
  Improve CI, track test coverage (#139)
  • Loading branch information
adzialocha committed May 31, 2022
2 parents f594be6 + f9375b0 commit 5842382
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
160 changes: 145 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,160 @@
name: tests
name: aquadoggo

on: push

env:
CARGO_TERM_COLOR: always
cache_path: |
target
~/.cargo
cargo_manifest: aquadoggo/Cargo.toml

jobs:
test:
name: build and test

rust-test-sqlite:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Cargo caching
uses: actions/cache@v2
- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
path: ${{ env.cache_path }}
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --verbose
- name: Build binary
uses: actions-rs/cargo@v1
with:
command: build
args: >-
--verbose
--manifest-path ${{ env.cargo_manifest }}
- name: Run tests
run: cargo test --verbose
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path ${{ env.cargo_manifest }}
# Ensure debug output is also tested
env:
RUST_LOG: debug

rust-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-check-${{ hashFiles('**/Cargo.lock') }}

- name: Check project and dependencies
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path ${{ env.cargo_manifest }}

rust-fmt:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-fmt-${{ hashFiles('**/Cargo.lock') }}

- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ${{ env.cargo_manifest }} -- --check

rust-clippy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-clippy-${{ hashFiles('**/Cargo.lock') }}

- name: Check code with clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --manifest-path ${{ env.cargo_manifest }} -- -D warnings --no-deps

rust-coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-tarpaulin-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
with:
# Force cleaning via `--force-clean` flag to prevent buggy code coverage
args: --manifest-path ${{ env.cargo_manifest }} --locked --force-clean
# Ensure debug output is also tested
env:
RUST_LOG: debug

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix high CPU usage of idle workers [#136](https://github.com/p2panda/aquadoggo/pull/136)
- Improve CI, track test coverage [#139](https://github.com/p2panda/aquadoggo/pull/139)

## [0.2.0]

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<a href="https://github.com/p2panda/aquadoggo/actions">
<img src="https://img.shields.io/github/workflow/status/p2panda/aquadoggo/tests?style=flat-square" alt="CI Status" />
</a>
<!-- Codecov report -->
<a href="https://app.codecov.io/gh/p2panda/aquadoggo/">
<img src="https://img.shields.io/codecov/c/gh/p2panda/aquadoggo?style=flat-square" alt="Codecov Report" />
</a>
<!-- Crates version -->
<a href="https://crates.io/crates/aquadoggo">
<img src="https://img.shields.io/crates/v/aquadoggo.svg?style=flat-square" alt="Crates.io version" />
Expand Down
3 changes: 2 additions & 1 deletion aquadoggo/src/db/models/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use sqlx::FromRow;
/// We store the u64 integer values of `log_id` as a string here since SQLite doesn't support
/// storing unsigned 64 bit integers.
#[derive(FromRow, Debug, Clone)]
pub struct LogRow {
#[allow(dead_code)]
pub struct Log {
/// Public key of the author.
pub author: String,

Expand Down
13 changes: 13 additions & 0 deletions aquadoggo/src/materializer/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct Task<IN>(WorkerName, IN);

impl<IN> Task<IN> {
/// Returns a new task.
#[allow(dead_code)]
pub fn new(worker_name: &str, input: IN) -> Self {
Self(worker_name.into(), input)
}
Expand All @@ -109,9 +110,11 @@ pub type TaskResult<IN> = Result<Option<Vec<Task<IN>>>, TaskError>;
/// Possible return values of a failed task.
pub enum TaskError {
/// This tasks failed critically and will cause the whole program to panic.
#[allow(dead_code)]
Critical,

/// This task failed silently without any further effects.
#[allow(dead_code)]
Failure,
}

Expand All @@ -120,6 +123,7 @@ pub type WorkerName = String;

/// Every registered worker pool is managed by a `WorkerManager` which holds the task queue for
/// this registered work and an index of all current inputs in the task queue.
#[allow(dead_code)]
struct WorkerManager<IN>
where
IN: Send + Sync + Clone + Hash + Eq + 'static,
Expand All @@ -139,6 +143,7 @@ where
IN: Send + Sync + Clone + Hash + Eq + 'static,
{
/// Returns a new worker manager.
#[allow(dead_code)]
pub fn new() -> Self {
Self {
input_index: Arc::new(Mutex::new(HashSet::new())),
Expand Down Expand Up @@ -186,6 +191,7 @@ where

/// Every queue consists of items which hold an unique identifier and the task input value.
#[derive(Debug)]
#[allow(dead_code)]
pub struct QueueItem<IN>
where
IN: Send + Sync + Clone + 'static,
Expand All @@ -202,22 +208,26 @@ where
IN: Send + Sync + Clone + 'static,
{
/// Returns a new queue item.
#[allow(dead_code)]
pub fn new(id: u64, input: IN) -> Self {
Self { id, input }
}

/// Returns unique identifier of this queue item.
#[allow(dead_code)]
pub fn id(&self) -> u64 {
self.id
}

/// Returns generic input values of this queue item.
#[allow(dead_code)]
pub fn input(&self) -> IN {
self.input.clone()
}
}

/// This factory serves as a main entry interface to dispatch, schedule and process tasks.
#[allow(dead_code)]
pub struct Factory<IN, D>
where
IN: Send + Sync + Clone + Hash + Eq + Debug + 'static,
Expand Down Expand Up @@ -277,6 +287,7 @@ where
///
/// Ideally worker functions should be idempotent: meaning the function won’t cause unintended
/// effects even if called multiple times with the same arguments.
#[allow(dead_code)]
pub fn register<W: Workable<IN, D> + Send + Sync + Copy + 'static>(
&mut self,
name: &str,
Expand All @@ -300,6 +311,7 @@ where
///
/// Tasks with duplicate input values which already exist in the queue will be silently
/// rejected.
#[allow(dead_code)]
pub fn queue(&mut self, task: Task<IN>) {
match self.tx.send(task) {
Err(err) => {
Expand All @@ -311,6 +323,7 @@ where
}

/// Returns true if there are no more tasks given for this worker pool.
#[allow(dead_code)]
pub fn is_empty(&self, name: &str) -> bool {
match self.managers.get(name) {
Some(manager) => manager.queue.is_empty(),
Expand Down

0 comments on commit 5842382

Please sign in to comment.