From 3fb1725301834836d87e493a20e0f61b05218de1 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 30 May 2024 13:20:00 +0200 Subject: [PATCH] add test --- crates/db_schema/src/source/instance.rs | 1 + crates/federate/src/worker.rs | 35 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/crates/db_schema/src/source/instance.rs b/crates/db_schema/src/source/instance.rs index 98e0d401b..9ee6b7066 100644 --- a/crates/db_schema/src/source/instance.rs +++ b/crates/db_schema/src/source/instance.rs @@ -35,4 +35,5 @@ pub struct InstanceForm { pub software: Option, pub version: Option, pub updated: Option>, + pub published: Option>, } diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index d92e8faab..b1ab03d42 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -224,6 +224,7 @@ impl InstanceWorker { // Activity send successful, mark instance as alive if it hasn't been updated in a while. let updated = self.target.updated.unwrap_or(self.target.published); + dbg!(&updated); if updated.add(Days::new(1)) < Utc::now() { self.target.updated = Some(Utc::now()); @@ -351,8 +352,6 @@ mod test { let sent = send_activity(data.person.actor_id.clone(), &data.context).await?; - sleep(WORK_FINISHED_RECHECK_DELAY * 2).await; - // receive for successfully sent activity let inbox_rcv = data.inbox_receiver.recv().await.unwrap(); let parsed_activity = serde_json::from_str::>(&inbox_rcv)?; @@ -377,6 +376,32 @@ mod test { Ok(()) } + #[tokio::test] + #[serial] + async fn test_update_instance() -> LemmyResult<()> { + let mut data = Data::init().await?; + + let published = DateTime::from_timestamp_nanos(0); + let form = InstanceForm::builder() + .domain(data.instance.domain.clone()) + .published(Some(published)) + .updated(None) + .build(); + Instance::update(&mut data.context.pool(), data.instance.id, form).await?; + + send_activity(data.person.actor_id.clone(), &data.context).await?; + data.inbox_receiver.recv().await.unwrap(); + + let instance = + Instance::read_or_create(&mut data.context.pool(), data.instance.domain.clone()).await?; + + assert!(instance.updated.is_some()); + + data.cleanup().await?; + + Ok(()) + } + async fn listen_activities( inbox_sender: UnboundedSender, cancel: CancellationToken, @@ -418,6 +443,10 @@ mod test { actor_type: ActorType::Person, actor_apub_id: actor_id, }; - Ok(SentActivity::create(&mut context.pool(), form).await?) + let sent = SentActivity::create(&mut context.pool(), form).await?; + + sleep(WORK_FINISHED_RECHECK_DELAY * 2).await; + + Ok(sent) } }