Skip to content

Commit

Permalink
Merge pull request #2 from PierreZ/prepare-release
Browse files Browse the repository at this point in the history
chore: coverage and doc
  • Loading branch information
PierreZ committed Jul 31, 2021
2 parents 719618b + f1d0d74 commit eee5df2
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 20 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Coverage

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
grcov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- uses: actions-rs/cargo@v1
with:
command: clean

- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast -- --test-threads=1 --show-output
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'

- uses: actions-rs/grcov@v0.1
- name: Run grcov
id: coverage
uses: actions-rs/grcov@v0.1
- name: Coveralls upload
uses: coverallsapp/github-action@v1.1.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.coverage.outputs.report }}
flag-name: test-${{ matrix.os }}
parallel: false
grcov_finalize:
runs-on: ubuntu-latest
needs: grcov
steps:
- name: Finalize Coveralls upload
uses: coverallsapp/github-action@v1.1.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A toolkit to develop distributed systems

## Overview

A crate that will provides a toolbox to create distributed systems in Rust.
A sets of crates that will provide toolboxes to create distributed systems in Rust.
Highly experimental for now, but the end-goal is to provide some of the helpers that the [FoundationDB's developers](https://www.foundationdb.org/) have:
* a [simulator](https://www.youtube.com/watch?v=4fFDFbi3toc)
* a [rpc framework](https://forums.foundationdb.org/t/why-was-flow-developed/1711/2) built using the simulator.
Expand Down
13 changes: 13 additions & 0 deletions simulation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ edition = "2018"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/PierreZ/circus"
homepage = "https://github.com/PierreZ/circus"


include = [
"../LICENSE-APACHE",
"../LICENSE-MIT",
"README.md",
".gitignore",
"Cargo.toml",
"src/*.rs",
"src/*/*.rs",
"tests/*.rs",
]

description = "Simulation framework inspired by FoundationDB"
categories = ["simulation"]
Expand Down
41 changes: 41 additions & 0 deletions simulation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# circus-simulation :circus_tent:
A toolkit to develop distributed systems

![status](https://img.shields.io/badge/status-experimental-red)
[![Build status](https://github.com/PierreZ/circus/workflows/Build%20and%20test/badge.svg)](https://github.com/PierreZ/circus/actions)
[![Coverage Status](https://coveralls.io/repos/github/PierreZ/circus/badge.svg?branch=main)](https://coveralls.io/github/PierreZ/circus?branch=main)
[![Dependency Status](https://deps.rs/repo/github/PierreZ/circus/status.svg)](https://deps.rs/repo/github/PierreZ/circus)
![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.42.0+-lightgray.svg)](#rust-version-requirements)

## Overview

A sets of crates that will provide toolboxes to create distributed systems in Rust.
Highly experimental for now, but the end-goal is to provide some of the helpers that the [FoundationDB's developers](https://www.foundationdb.org/) have:
* a [simulator](https://www.youtube.com/watch?v=4fFDFbi3toc)
* a [rpc framework](https://forums.foundationdb.org/t/why-was-flow-developed/1711/2) built using the simulator.

It will be compatible with both `async-std` and `Tokio`, allowing you to use Circus during development, then switch to your favorite runtime in production.

## Rust version requirements

The MSRV is Rust 1.42.0.

## Examples

Examples can be found in the [examples folder](simulation/examples).

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
5 changes: 1 addition & 4 deletions simulation/examples/buggify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ extern crate circus_simulation;
use circus_simulation::buggify;
use circus_simulation::buggify::*;
use circus_simulation::deterministic::random::Random;
use std::ops::Deref;
use tracing::{span, Level};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter, Registry};
use tracing::Level;

fn main() {
// init random with a seed
Expand Down
81 changes: 69 additions & 12 deletions simulation/src/buggify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Default for Buggifier {
/// Create a new Buggifier
fn default() -> Self {
Buggifier {
buggified_lines: Default::default(),
buggified_lines: Mutex::new(HashMap::new()),
random: Default::default(),
}
}
Expand All @@ -62,6 +62,8 @@ pub fn disable_buggify() {
tracing::info!("disabling buggify");
let mut data = BUGGIFIER_INSTANCE.random.lock();
*data = None;
let mut map = BUGGIFIER_INSTANCE.buggified_lines.lock();
map.clear();
}

#[macro_export]
Expand All @@ -72,35 +74,74 @@ pub fn disable_buggify() {
/// 1. Enabled uses of `buggify!` have a 5% chance of evaluating to true
///
/// A good blogpost about buggify can be found [here](https://transactional.blog/simulation/buggify.html).
///
/// ## Getting started with `buggify!`
///
/// ```rust
/// extern crate circus_simulation;
///
/// use circus_simulation::buggify;
/// use circus_simulation::buggify::*;
/// use circus_simulation::deterministic::random::Random;
/// use tracing::Level;
///
/// fn main() {
/// // init random with a seed
/// let random = Random::new_with_seed(42);
///
/// tracing_subscriber::fmt()
/// .with_max_level(Level::DEBUG)
/// .init();
///
/// // enables buggify
/// enable_buggify(random);
///
/// for i in 0..10 {
/// // this block has a 0.05% chance to be run
/// // which is iteration 8 for seed 42
/// if buggify!() {
/// tracing::info!("buggified at iteration {}", i);
/// }
/// }
///
/// // buggify can also accept a probability
/// if buggify!(1.0) {
/// tracing::info!("buggified with a 100% probability!");
/// }
/// }
/// ```
///
macro_rules! buggify {
($probability:expr) => {{
let line = format!("{}:{},{}", file!(), line!(), column!());
let line = format!("{}:{}", file!(), line!());
handle_buggify(line, $probability)
}};
() => {{
let line = format!("{}:{},{}", file!(), line!(), column!());
let line = format!("{}:{}", file!(), line!());
handle_buggify(line, 0.05)
}};
}
#[cfg(test)]
mod tests {

use crate::buggify::BUGGIFIER_INSTANCE;
use crate::buggify::*;
use crate::deterministic::random::Random;
use parking_lot::Once;
use std::borrow::BorrowMut;
use std::sync::{MutexGuard, PoisonError};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter, Registry};

#[test]
fn test_macro() {
assert!(!is_buggify_enabled());
for i in 0..9999 {
assert!(!buggify!(), "should not buggified");
assert!(!buggify!(1.0), "should not buggified");

{
let data = BUGGIFIER_INSTANCE.random.lock();
assert!((*data).is_none());

let map = BUGGIFIER_INSTANCE.buggified_lines.lock();
assert!((*map).is_empty());
}

let mut random = Random::new_with_seed(42);
let random = Random::new_with_seed(42);
enable_buggify(random);

assert!(is_buggify_enabled(), "should be activated");
Expand All @@ -110,6 +151,22 @@ mod tests {
assert_eq!(buggify!(), result, "{} should have been {}", i, result);
}

assert!(buggify!(1.0), "probility of 1.0 should always be fired")
{
dbg!(&BUGGIFIER_INSTANCE);
let data = BUGGIFIER_INSTANCE.random.lock();
assert!((*data).is_some());

let map = BUGGIFIER_INSTANCE.buggified_lines.lock();
assert_eq!((*map).len(), 1);
for key in (*map).keys() {
assert!(key.starts_with("simulation/src/buggify.rs:"));
}
for value in (*map).values() {
assert!(value);
}
}

disable_buggify();
assert!(!buggify!(1.0), "should not buggified");
}
}
2 changes: 1 addition & 1 deletion simulation/src/deterministic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! deterministic modules
//! Deterministic scheduling, IO and fault injection
pub mod random;
#[allow(dead_code)]
pub mod time;
2 changes: 1 addition & 1 deletion simulation/src/deterministic/random.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Random module
//! Deterministic randomness
use std::ops::Range;

use parking_lot::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/deterministic/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! time module
//! Deterministic time
use std::time;

#[derive(Debug)]
Expand Down
2 changes: 2 additions & 0 deletions simulation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! * a [simulator](https://www.youtube.com/watch?v=4fFDFbi3toc)
//! * a [rpc framework](https://forums.foundationdb.org/t/why-was-flow-developed/1711/2) built using the simulator
//! It will be compatible with both `async-std` and `Tokio`, allowing you to use Circus during development, then switch to your favorite runtime in production.
//!
//! Examples can be found in the [examples folder](https://github.com/PierreZ/circus/tree/main/simulation/examples).

pub mod buggify;
pub mod deterministic;

0 comments on commit eee5df2

Please sign in to comment.