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

Faster testing

This commit is contained in:
Felix Ableitner 2024-12-05 12:07:20 +01:00
parent 0c3b5ca65a
commit e0ed85daf2
4 changed files with 27 additions and 12 deletions

View file

@ -51,7 +51,7 @@ use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use log::info;
use std::net::SocketAddr;
use tokio::net::TcpListener;
use tokio::{net::TcpListener, sync::oneshot};
use tower_http::cors::CorsLayer;
use tower_layer::Layer;
@ -68,7 +68,11 @@ const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
const FEDERATION_ROUTES_PREFIX: &str = "/federation_routes";
pub async fn start(config: IbisConfig, override_hostname: Option<SocketAddr>) -> MyResult<()> {
pub async fn start(
config: IbisConfig,
override_hostname: Option<SocketAddr>,
notify_start: Option<oneshot::Sender<()>>,
) -> MyResult<()> {
let manager = ConnectionManager::<PgConnection>::new(&config.database.connection_url);
let db_pool = Pool::builder()
.max_size(config.database.pool_size)
@ -118,6 +122,9 @@ pub async fn start(config: IbisConfig, override_hostname: Option<SocketAddr>) ->
info!("Listening on {}", &addr);
let listener = TcpListener::bind(&addr).await?;
if let Some(notify_start) = notify_start {
notify_start.send(()).expect("send oneshot");
}
axum::serve(listener, app_with_middleware.into_make_service()).await?;
Ok(())

View file

@ -66,7 +66,7 @@ impl<T: Default + Send + Sync + Clone> DefaultResource<T> for Resource<T> {
}
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />

View file

@ -16,6 +16,6 @@ pub async fn main() -> ibis::backend::error::MyResult<()> {
.init();
let ibis_config = IbisConfig::read()?;
ibis::backend::start(ibis_config, None).await?;
ibis::backend::start(ibis_config, None, None).await?;
Ok(())
}

View file

@ -16,17 +16,19 @@ use std::{
ops::Deref,
process::{Command, Stdio},
sync::{
atomic::{AtomicI32, Ordering},
atomic::{AtomicI32, AtomicUsize, Ordering},
Once,
},
thread::{sleep, spawn},
thread::{available_parallelism, sleep, spawn},
time::Duration,
};
use tokio::{join, task::JoinHandle};
use tokio::{join, sync::oneshot, task::JoinHandle};
use tracing::log::LevelFilter;
pub struct TestData(pub IbisInstance, pub IbisInstance, pub IbisInstance);
static ACTIVE_TESTS: AtomicUsize = AtomicUsize::new(0);
impl TestData {
pub async fn start(article_approval: bool) -> Self {
static INIT: Once = Once::new();
@ -42,8 +44,12 @@ impl TestData {
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 * 2000));
// Limit number of parallel test runs based on number of cpu cores
let cores = available_parallelism().unwrap().get();
while ACTIVE_TESTS.load(Ordering::Acquire) >= cores {
sleep(Duration::from_millis(1000));
}
ACTIVE_TESTS.fetch_add(1, Ordering::AcqRel);
let first_port = 8100 + (current_run * 3);
let port_alpha = first_port;
@ -76,6 +82,7 @@ impl TestData {
for j in [alpha.stop(), beta.stop(), gamma.stop()] {
j.join().unwrap();
}
ACTIVE_TESTS.fetch_sub(1, Ordering::AcqRel);
Ok(())
}
}
@ -133,13 +140,14 @@ impl IbisInstance {
};
let client = ClientBuilder::new().cookie_store(true).build().unwrap();
let api_client = ApiClient::new(client, Some(domain));
let (tx, rx) = oneshot::channel::<()>();
let handle = tokio::task::spawn(async move {
start(config, Some(hostname.parse().unwrap()))
start(config, Some(hostname.parse().unwrap()), Some(tx))
.await
.unwrap();
});
// wait a moment for the backend to start
tokio::time::sleep(Duration::from_millis(5000)).await;
// wait for the backend to start
rx.await.unwrap();
let form = RegisterUserForm {
username: username.to_string(),
password: "hunter2".to_string(),