1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-12-23 14:11:23 +00:00

run tests in parallel

This commit is contained in:
Felix Ableitner 2023-12-04 02:42:53 +01:00
parent 181b585644
commit 00319546a4
4 changed files with 27 additions and 60 deletions

39
Cargo.lock generated
View file

@ -449,19 +449,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "dashmap"
version = "5.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if",
"hashbrown 0.14.2",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]]
name = "derive_builder"
version = "0.12.0"
@ -696,7 +683,6 @@ dependencies = [
"rand",
"reqwest",
"serde",
"serial_test",
"sha2",
"tokio",
"tracing",
@ -1880,31 +1866,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serial_test"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e56dd856803e253c8f298af3f4d7eb0ae5e23a737252cd90bb4f3b435033b2d"
dependencies = [
"dashmap",
"futures",
"lazy_static",
"log",
"parking_lot",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "sha1"
version = "0.10.6"

View file

@ -28,4 +28,3 @@ url = "2.4.1"
once_cell = "1.18.0"
pretty_assertions = "1.4.0"
reqwest = "0.11.22"
serial_test = "2.0.0"

View file

@ -11,8 +11,10 @@ use serde::de::Deserialize;
use serde::ser::Serialize;
use std::env::current_dir;
use std::process::{Command, Stdio};
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Once;
use std::thread::spawn;
use std::thread::{sleep, spawn};
use std::time::Duration;
use tokio::task::JoinHandle;
use tracing::log::LevelFilter;
use url::Url;
@ -36,9 +38,21 @@ impl TestData {
.init();
});
let alpha_db_path = generate_db_path("alpha");
let beta_db_path = generate_db_path("beta");
let gamma_db_path = generate_db_path("gamma");
// Run things on different ports and db paths to allow parallel tests
static COUNTER: AtomicI32 = AtomicI32::new(0);
let current_run = COUNTER.fetch_add(1, Ordering::Relaxed);
// Give each test a moment to start its postgres databases
sleep(Duration::from_millis(current_run as u64 * 500));
let first_port = 8000 + (current_run * 3);
let port_alpha = first_port;
let port_beta = first_port + 1;
let port_gamma = first_port + 2;
let alpha_db_path = generate_db_path("alpha", port_alpha);
let beta_db_path = generate_db_path("beta", port_beta);
let gamma_db_path = generate_db_path("gamma", port_gamma);
// initialize postgres databases in parallel because its slow
for j in [
@ -50,9 +64,9 @@ impl TestData {
}
Self {
alpha: FediwikiInstance::start(alpha_db_path, 8131),
beta: FediwikiInstance::start(beta_db_path, 8132),
gamma: FediwikiInstance::start(gamma_db_path, 8133),
alpha: FediwikiInstance::start(alpha_db_path, port_alpha),
beta: FediwikiInstance::start(beta_db_path, port_beta),
gamma: FediwikiInstance::start(gamma_db_path, port_gamma),
}
}
@ -64,8 +78,12 @@ impl TestData {
}
}
fn generate_db_path(name: &'static str) -> String {
format!("{}/target/test_db/{name}", current_dir().unwrap().display())
/// Generate a unique db path for each postgres so that tests can run in parallel.
fn generate_db_path(name: &'static str, port: i32) -> String {
format!(
"{}/target/test_db/{name}-{port}",
current_dir().unwrap().display()
)
}
pub struct FediwikiInstance {

View file

@ -15,11 +15,9 @@ use fediwiki::error::MyResult;
use fediwiki::federation::objects::instance::DbInstance;
use pretty_assertions::{assert_eq, assert_ne};
use serial_test::serial;
use url::Url;
#[tokio::test]
#[serial]
async fn test_create_read_and_edit_article() -> MyResult<()> {
let data = TestData::start();
@ -62,7 +60,6 @@ async fn test_create_read_and_edit_article() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_create_duplicate_article() -> MyResult<()> {
let data = TestData::start();
@ -79,7 +76,6 @@ async fn test_create_duplicate_article() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_follow_instance() -> MyResult<()> {
let data = TestData::start();
@ -102,7 +98,6 @@ async fn test_follow_instance() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_synchronize_articles() -> MyResult<()> {
let data = TestData::start();
@ -149,7 +144,6 @@ async fn test_synchronize_articles() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_edit_local_article() -> MyResult<()> {
let data = TestData::start();
@ -193,7 +187,6 @@ async fn test_edit_local_article() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_edit_remote_article() -> MyResult<()> {
let data = TestData::start();
@ -246,7 +239,6 @@ async fn test_edit_remote_article() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_local_edit_conflict() -> MyResult<()> {
let data = TestData::start();
@ -301,7 +293,6 @@ async fn test_local_edit_conflict() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_federated_edit_conflict() -> MyResult<()> {
let data = TestData::start();
@ -383,7 +374,6 @@ async fn test_federated_edit_conflict() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_overlapping_edits_no_conflict() -> MyResult<()> {
let data = TestData::start();
@ -422,7 +412,6 @@ async fn test_overlapping_edits_no_conflict() -> MyResult<()> {
}
#[tokio::test]
#[serial]
async fn test_fork_article() -> MyResult<()> {
let data = TestData::start();