federation-send-parallel
phiresky 2024-06-29 19:29:35 +02:00
parent 76c6487390
commit 0f5b69cffc
3 changed files with 7 additions and 13 deletions

View File

@ -70,7 +70,8 @@ impl LemmyContext {
let rate_limit_cell = RateLimitCell::with_test_config(); let rate_limit_cell = RateLimitCell::with_test_config();
let context = LemmyContext::create(pool, client, secret, rate_limit_cell.clone()); let context = LemmyContext::create(pool, client, secret, rate_limit_cell.clone());
let config = FederationConfig::builder()
FederationConfig::builder()
.domain(context.settings().hostname.clone()) .domain(context.settings().hostname.clone())
.app_data(context) .app_data(context)
.debug(true) .debug(true)
@ -78,8 +79,7 @@ impl LemmyContext {
.http_fetch_limit(0) .http_fetch_limit(0)
.build() .build()
.await .await
.expect("build federation config"); .expect("build federation config")
return config;
} }
pub async fn init_test_context() -> Data<LemmyContext> { pub async fn init_test_context() -> Data<LemmyContext> {
let config = Self::init_test_federation_config().await; let config = Self::init_test_federation_config().await;

View File

@ -422,10 +422,8 @@ mod test {
use std::{fs::File, io::BufReader}; use std::{fs::File, io::BufReader};
use test_context::{test_context, AsyncTestContext}; use test_context::{test_context, AsyncTestContext};
use tokio::{ use tokio::{
select,
spawn, spawn,
sync::mpsc::{error::TryRecvError, unbounded_channel, UnboundedReceiver}, sync::mpsc::{error::TryRecvError, unbounded_channel, UnboundedReceiver},
task::JoinHandle,
}; };
use tracing_test::traced_test; use tracing_test::traced_test;
use url::Url; use url::Url;
@ -462,8 +460,7 @@ mod test {
let (inbox_sender, inbox_receiver) = unbounded_channel(); let (inbox_sender, inbox_receiver) = unbounded_channel();
// listen for received activities in background // listen for received activities in background
let cancel_ = cancel.clone(); let wait_stop_server = listen_activities(inbox_sender)?;
let wait_stop_server = listen_activities(inbox_sender, cancel_)?;
let fed_config = FederationWorkerConfig { let fed_config = FederationWorkerConfig {
concurrent_sends_per_instance: 1, concurrent_sends_per_instance: 1,
@ -578,10 +575,7 @@ mod test {
Ok(()) Ok(())
} }
fn listen_activities( fn listen_activities(inbox_sender: UnboundedSender<String>) -> LemmyResult<ServerHandle> {
inbox_sender: UnboundedSender<String>,
cancel: CancellationToken,
) -> LemmyResult<ServerHandle> {
let run = HttpServer::new(move || { let run = HttpServer::new(move || {
App::new() App::new()
.app_data(actix_web::web::Data::new(inbox_sender.clone())) .app_data(actix_web::web::Data::new(inbox_sender.clone()))
@ -616,7 +610,7 @@ mod test {
let form = SentActivityForm { let form = SentActivityForm {
ap_id: Url::parse(&format!( ap_id: Url::parse(&format!(
"http://local.com/activity/{}", "http://local.com/activity/{}",
uuid::Uuid::new_v4().to_string() uuid::Uuid::new_v4()
))? ))?
.into(), .into(),
data: serde_json::from_reader(reader)?, data: serde_json::from_reader(reader)?,