Skip to content
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

Fix test-runner race conditions #269

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix race-condition of mutably shared static schema store during testing [#269](https://github.com/p2panda/aquadoggo/pull/269)

## [0.4.0]

### Added
Expand Down
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aquadoggo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ reqwest = { version = "^0.11.11", default-features = false, features = [
rstest = "^0.15.0"
rstest_reuse = "^0.3.0"
serde_json = "^1.0.85"
serial_test = "1.0.0"
tower = "^0.4.13"
tower-service = "^0.3.2"
2 changes: 1 addition & 1 deletion aquadoggo/src/db/stores/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ mod tests {
use p2panda_rs::operation::traits::AsOperation;
use p2panda_rs::operation::{Operation, OperationId};
use p2panda_rs::storage_provider::traits::StorageProvider;
use p2panda_rs::test_utils::constants::{self};
use p2panda_rs::test_utils::constants;
use p2panda_rs::test_utils::fixtures::{
operation, random_document_view_id, random_operation_id,
};
Expand Down
10 changes: 10 additions & 0 deletions aquadoggo/src/graphql/client/dynamic_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,20 @@ mod test {
use p2panda_rs::test_utils::fixtures::random_key_pair;
use rstest::rstest;
use serde_json::json;
use serial_test::serial;

use crate::db::stores::test_utils::{
add_document, add_schema, test_db, TestDatabase, TestDatabaseRunner,
};
use crate::test_helpers::graphql_test_client;

#[rstest]
// Note: This and more tests in this file use the underlying static schema provider which is a
// static mutable data store, accessible across all test runner threads in parallel mode. To
// prevent overwriting data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
fn single_query(#[from(test_db)] runner: TestDatabaseRunner) {
// Test single query parameter variations.

Expand Down Expand Up @@ -482,6 +489,7 @@ mod test {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
#[case::unknown_document_id(
"id: \"00208f7492d6eb01360a886dac93da88982029484d8c04a0bd2ac0607101b80a6634\"",
value!({
Expand Down Expand Up @@ -555,6 +563,7 @@ mod test {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn collection_query(#[from(test_db)] runner: TestDatabaseRunner) {
// Test collection query parameter variations.

Expand Down Expand Up @@ -602,6 +611,7 @@ mod test {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn type_name(#[from(test_db)] runner: TestDatabaseRunner) {
// Test availability of `__typename` on all objects.

Expand Down
10 changes: 10 additions & 0 deletions aquadoggo/src/graphql/client/dynamic_types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ use p2panda_rs::schema::{FieldType, SchemaId, SYSTEM_SCHEMAS};
use p2panda_rs::test_utils::fixtures::random_key_pair;
use rstest::rstest;
use serde_json::json;
use serial_test::serial;

use crate::db::stores::test_utils::{add_schema, test_db, TestDatabase, TestDatabaseRunner};
use crate::test_helpers::graphql_test_client;

#[rstest]
// Note: This and more tests in this file use the underlying static schema provider which is a
// static mutable data store, accessible across all test runner threads in parallel mode. To
// prevent overwriting data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
#[case(SYSTEM_SCHEMAS[0].id().to_string(), SYSTEM_SCHEMAS[0].description().to_string())]
#[case(SYSTEM_SCHEMAS[1].id().to_string(), SYSTEM_SCHEMAS[1].description().to_string())]
fn system_schema_container_type(
Expand Down Expand Up @@ -71,6 +78,7 @@ fn system_schema_container_type(
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn application_schema_container_type(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |mut db: TestDatabase| async move {
let key_pair = random_key_pair();
Expand Down Expand Up @@ -137,6 +145,7 @@ fn application_schema_container_type(#[from(test_db)] runner: TestDatabaseRunner
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn application_schema_fields_type(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |mut db: TestDatabase| async move {
let key_pair = random_key_pair();
Expand Down Expand Up @@ -220,6 +229,7 @@ fn application_schema_fields_type(#[from(test_db)] runner: TestDatabaseRunner) {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn metadata_type(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |db: TestDatabase| async move {
let client = graphql_test_client(&db).await;
Expand Down
14 changes: 14 additions & 0 deletions aquadoggo/src/graphql/client/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ mod tests {
};
use rstest::{fixture, rstest};
use serde_json::json;
use serial_test::serial;
use tokio::sync::broadcast;

use crate::bus::ServiceMessage;
Expand Down Expand Up @@ -198,6 +199,12 @@ mod tests {
}

#[rstest]
// Note: This and more tests in this file use the underlying static schema provider which is a
// static mutable data store, accessible across all test runner threads in parallel mode. To
// prevent overwriting data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
fn publish_entry(
#[from(test_db)]
#[with(0, 0, 0, false, test_schema())]
Expand Down Expand Up @@ -226,6 +233,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn sends_message_on_communication_bus(
#[from(test_db)]
#[with(0, 0, 0, false, test_schema())]
Expand Down Expand Up @@ -253,6 +261,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn post_gql_mutation(
#[from(test_db)]
#[with(0, 0, 0, false, test_schema())]
Expand Down Expand Up @@ -291,6 +300,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
#[case::invalid_entry_bytes(
"AB01",
&OPERATION_ENCODED,
Expand Down Expand Up @@ -507,6 +517,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
#[case::backlink_and_skiplink_not_in_db(
&entry_signed_encoded_unvalidated(
8,
Expand Down Expand Up @@ -637,6 +648,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn publish_many_entries(
#[from(test_db)]
#[with(0, 0, 0, false, doggo_schema())]
Expand Down Expand Up @@ -726,6 +738,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn duplicate_publishing_of_entries(
#[from(test_db)]
#[with(1, 1, 1, false, doggo_schema())]
Expand Down Expand Up @@ -770,6 +783,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn publish_unsupported_schema(
#[from(encoded_entry)] entry_with_unsupported_schema: EncodedEntry,
#[from(encoded_operation)] operation_with_unsupported_schema: EncodedOperation,
Expand Down
10 changes: 10 additions & 0 deletions aquadoggo/src/graphql/client/static_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ mod tests {
use async_graphql::{value, Response};
use rstest::rstest;
use serde_json::json;
use serial_test::serial;

use crate::db::stores::test_utils::{test_db, TestDatabase, TestDatabaseRunner};
use crate::test_helpers::graphql_test_client;

#[rstest]
// Note: This and more tests in this file use the underlying static schema provider which is a
// static mutable data store, accessible across all test runner threads in parallel mode. To
// prevent overwriting data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
fn next_args_valid_query(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |db: TestDatabase| async move {
let client = graphql_test_client(&db).await;
Expand Down Expand Up @@ -92,7 +99,9 @@ mod tests {
);
})
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn next_args_valid_query_with_document_id(
#[with(1, 1, 1)]
#[from(test_db)]
Expand Down Expand Up @@ -146,6 +155,7 @@ mod tests {
}

#[rstest]
#[serial] // See note above on why we execute this test in series
fn next_args_error_response(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |db: TestDatabase| async move {
let client = graphql_test_client(&db).await;
Expand Down
8 changes: 8 additions & 0 deletions aquadoggo/src/graphql/client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use p2panda_rs::schema::FieldType;
use p2panda_rs::test_utils::fixtures::random_key_pair;
use rstest::rstest;
use serde_json::json;
use serial_test::serial;

use crate::db::stores::test_utils::{
add_document, add_schema, test_db, TestDatabase, TestDatabaseRunner,
Expand All @@ -18,6 +19,12 @@ use crate::test_helpers::graphql_test_client;
// Test querying application documents with scalar fields (no relations) by document id and by view
// id.
#[rstest]
// Note: This and more tests in this file use the underlying static schema provider which is a
// static mutable data store, accessible across all test runner threads in parallel mode. To
// prevent overwriting data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
fn scalar_fields(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(&|mut db: TestDatabase| async move {
let key_pair = random_key_pair();
Expand Down Expand Up @@ -91,6 +98,7 @@ fn scalar_fields(#[from(test_db)] runner: TestDatabaseRunner) {
// Test querying application documents across a parent-child relation using different kinds of
// relation fields.
#[rstest]
#[serial] // See note above on why we execute this test in series
fn relation_fields(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(&|mut db: TestDatabase| async move {
let key_pair = random_key_pair();
Expand Down
7 changes: 7 additions & 0 deletions aquadoggo/src/graphql/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,18 @@ mod test {
use p2panda_rs::test_utils::fixtures::key_pair;
use rstest::rstest;
use serde_json::{json, Value};
use serial_test::serial;

use crate::db::stores::test_utils::{add_schema, test_db, TestDatabase, TestDatabaseRunner};
use crate::test_helpers::graphql_test_client;

#[rstest]
// Note: This test uses the underlying static schema provider which is a static mutable data
// store, accessible across all test runner threads in parallel mode. To prevent overwriting
// data across threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
fn schema_updates(#[from(test_db)] runner: TestDatabaseRunner) {
runner.with_db_teardown(move |mut db: TestDatabase| async move {
// Create test client in the beginning so it is initialised with just the system
Expand Down
7 changes: 7 additions & 0 deletions aquadoggo/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ use p2panda_rs::operation::{Operation, OperationAction, OperationBuilder};
use p2panda_rs::schema::{FieldType, Schema, SchemaId};
use reqwest::Client;
use serde_json::{json, Map, Value};
use serial_test::serial;

use crate::{Configuration, Node};

#[tokio::test]
// Note: This test uses the underlying static schema provider which is a static mutable data store,
// accessible across all test runner threads in parallel mode. To prevent overwriting data across
// threads we have to run this test in serial.
//
// Read more: https://users.rust-lang.org/t/static-mutables-in-tests/49321
#[serial]
async fn e2e() {
// This is an aquadoggo E2E test.
//
Expand Down