mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-27 13:21:32 +00:00
cleanup
This commit is contained in:
parent
86d3550901
commit
a56c3de124
1 changed files with 23 additions and 10 deletions
|
@ -152,13 +152,17 @@ impl SendManager {
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use tokio::{spawn, time::sleep};
|
use activitypub_federation::config::Data;
|
||||||
|
use tokio::{spawn, time::sleep};
|
||||||
|
|
||||||
#[tokio::test]
|
struct TestData {
|
||||||
async fn test_start_stop_federation_workers() -> LemmyResult<()> {
|
send_manager: SendManager,
|
||||||
// initialization
|
context: Data<LemmyContext>,
|
||||||
|
instances: Vec<Instance>
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init() -> LemmyResult<TestData> {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let pool = &mut context.pool();
|
|
||||||
let opts = Opts {
|
let opts = Opts {
|
||||||
process_count: 1,
|
process_count: 1,
|
||||||
process_index: 1,
|
process_index: 1,
|
||||||
|
@ -169,30 +173,39 @@ mod test {
|
||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let pool = &mut context.pool();
|
||||||
let instances = vec![
|
let instances = vec![
|
||||||
Instance::read_or_create(pool, "alpha.com".to_string()).await?,
|
Instance::read_or_create(pool, "alpha.com".to_string()).await?,
|
||||||
Instance::read_or_create(pool, "beta.com".to_string()).await?,
|
Instance::read_or_create(pool, "beta.com".to_string()).await?,
|
||||||
Instance::read_or_create(pool, "gamma.com".to_string()).await?,
|
Instance::read_or_create(pool, "gamma.com".to_string()).await?,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let send_manager = SendManager::new(opts, federation_config);
|
||||||
|
Ok(TestData {send_manager,
|
||||||
|
context,instances
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_start_stop_federation_workers() -> LemmyResult<()> {
|
||||||
|
let mut data = init().await?;
|
||||||
|
|
||||||
// start it and wait a moment
|
// start it and wait a moment
|
||||||
let mut task = SendManager::new(opts, federation_config);
|
|
||||||
let cancel = CancellationToken::new();
|
let cancel = CancellationToken::new();
|
||||||
let cancel_ = cancel.clone();
|
let cancel_ = cancel.clone();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
sleep(Duration::from_millis(100)).await;
|
sleep(Duration::from_millis(100)).await;
|
||||||
cancel_.cancel();
|
cancel_.cancel();
|
||||||
});
|
});
|
||||||
task.do_loop(cancel.clone()).await.unwrap();
|
data.send_manager.do_loop(cancel.clone()).await.unwrap();
|
||||||
assert_eq!(3, task.workers.len());
|
assert_eq!(3, data.send_manager.workers.len());
|
||||||
|
|
||||||
// check that correct number of instance workers was started
|
// check that correct number of instance workers was started
|
||||||
// TODO: need to wrap in Arc or something similar
|
// TODO: need to wrap in Arc or something similar
|
||||||
// TODO: test with different `opts`, dead/blocked instances etc
|
// TODO: test with different `opts`, dead/blocked instances etc
|
||||||
//assert_eq!(3, task.workers.len());
|
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
Instance::delete_all(pool).await?;
|
Instance::delete_all(&mut data.context.pool()).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue