Skip to content

Commit

Permalink
#337 code coverage in contribute, action script #338 try nextest (#339)
Browse files Browse the repository at this point in the history
* #337 code coverage in contribute, action script #338 try nextest

* #337 use nightly for coverage

* #337 llvm-tools

* #338 random_string fix test, add retries

* #337 gtk in codecov

* #340 playwright
  • Loading branch information
joepio committed Mar 23, 2022
1 parent 6e796d1 commit 6f5585b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 22 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0 libappindicator3-dev
- uses: actions/checkout@v2
- uses: taiki-e/install-action@nextest
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -39,8 +40,29 @@ jobs:
uses: Swatinem/rust-cache@v1.3.0
- uses: actions-rs/cargo@v1
with:
command: test
command: nextest
args: run --all-features --retries 3

coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0 libappindicator3-dev
- uses: actions/checkout@v2
- name: Install Rust and llvm-tools-preview
run: rustup toolchain install nightly --component llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate 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:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down Expand Up @@ -107,4 +129,4 @@ jobs:
command: build
args: --locked
- run: nohup ./target/debug/atomic-server &
- run: cd server/e2e_tests/ && npm i && npm run test
- run: cd server/e2e_tests/ && npm i && npx playwright install && npm run test
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ By far most changes relate to `atomic-server`, so if not specified, assume the c
- Rename `src-tauri` to `desktop` and make the tauri code part of the cargo workspace
- In Queries, respect a `limit` of `None` and `include_external` #317
- Run end-to-end tests from `atomic-data-browser` in `atomic-data-rust` CI #204
- Use `nextest` for testing #338
- Improve and monitor test coverage #337

## [v0.31.0] - 2022-01-25

Expand Down
26 changes: 23 additions & 3 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you want to share some thoughts on the Atomic Data _specification_, please [d
- [Table of contents](#table-of-contents)
- [Running locally](#running-locally)
- [Testing](#testing)
- [Code coverage](#code-coverage)
- [Debugging](#debugging)
- [Performance monitoring](#performance-monitoring)
- [Tracing](#tracing)
Expand Down Expand Up @@ -40,10 +41,22 @@ Since `atomic-server` is developed in conjunction with the typescript / react `a
## Testing

```sh
# Make sure nextest is installed
cargo install nextest
# This also makes sure that cli and server work, plus it test the db feature
cargo test --all
# Run specific tests
cargo test --all-features --package atomic_lib --lib -- db::test::testname
cargo nextest run
# Run specific test(s)
cargo nextest run test_name_substring
# End-to-end tests, powered by PlayWright and Atomic-Data-Browser
cd server/e2e_tests/ && npm i && npm run test
```

## Code coverage

```sh
# install cargo-llvm-cov, see https://github.com/taiki-e/cargo-llvm-cov
# Run the tests with a coverage report
cargo llvm-cov --all-features --show-missing-lines
```

## Debugging
Expand Down Expand Up @@ -153,6 +166,13 @@ or do it manually:
1. `ssh atomic` (@joepio manages server)
2. `service atomic restart`

```sh
# logs
journalctl -u atomic.service
# logs, since one hour, follow
journalctl -u atomic.service --since "1 hour ago" -f
```

## Publishing atomic-cli to WAPM

1. Install `wasmer` and `cargo-wasi`.
Expand Down
10 changes: 1 addition & 9 deletions lib/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
//! Should be run using `cargo criterion` or `cargo bench --all-features`.
//! See contribute.md for more information.

use atomic_lib::utils::random_string;
use atomic_lib::*;
use criterion::{criterion_group, criterion_main, Criterion};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};

fn random_string(n: usize) -> String {
let rand_string: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(n)
.map(char::from)
.collect();
rand_string
}

fn random_atom() -> Atom {
Atom::new(
format!("https://localhost/{}", random_string(10)),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl Db {
Ok(store)
}

/// Create a temporary Db. Useful for testing.
/// Create a temporary Db in `.temp/db/{id}`. Useful for testing.
/// Populates the database, creates a default agent, and sets the server_url to "http://localhost/".
pub fn init_temp(id: &str) -> AtomicResult<Db> {
let tmp_dir_path = format!(".temp/db/{}", id);
let _try_remove_existing = std::fs::remove_dir_all(&tmp_dir_path);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/db/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn queries() {
demo_resource
.set_propval(
sort_by.into(),
Value::Markdown(crate::utils::random_string()),
Value::Markdown(crate::utils::random_string(10)),
store,
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Resource {

/// Create a new resource with a generated Subject
pub fn new_generate_subject(store: &impl Storelike) -> Resource {
let generated = format!("{}/{}", store.get_server_url(), random_string());
let generated = format!("{}/{}", store.get_server_url(), random_string(10));

Resource::new(generated)
}
Expand All @@ -175,7 +175,7 @@ impl Resource {
"{}/{}/{}",
store.get_server_url(),
&class.shortname,
random_string()
random_string(10)
);
let mut resource = Resource {
propvals,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub fn now() -> i64 {
.as_millis() as i64
}

/// Generates a relatively short random string
pub fn random_string() -> String {
/// Generates a relatively short random string of n length
pub fn random_string(n: usize) -> String {
use rand::Rng;
let random_string: String = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(7)
.take(n)
.map(char::from)
.collect();
random_string.to_lowercase()
Expand Down
8 changes: 7 additions & 1 deletion server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ fn build_request_authenticated(path: &str, appstate: &AppState) -> TestRequest {

#[actix_rt::test]
async fn server_tests() {
let opts = Opts::parse_from(&["atomic-server", "--initialize", "--config-dir", "./.temp"]);
let unique_string = atomic_lib::utils::random_string(10);
let opts = Opts::parse_from(&[
"atomic-server",
"--initialize",
"--config-dir",
&format!("./.temp/{}", unique_string),
]);
let config = config::build_config(opts)
.map_err(|e| format!("Initialization failed: {}", e))
.expect("failed init config");
Expand Down

0 comments on commit 6f5585b

Please sign in to comment.