mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 03:11:08 +00:00
add test
This commit is contained in:
parent
7bcc6f2894
commit
3fb1725301
2 changed files with 33 additions and 3 deletions
|
@ -35,4 +35,5 @@ pub struct InstanceForm {
|
||||||
pub software: Option<String>,
|
pub software: Option<String>,
|
||||||
pub version: Option<String>,
|
pub version: Option<String>,
|
||||||
pub updated: Option<DateTime<Utc>>,
|
pub updated: Option<DateTime<Utc>>,
|
||||||
|
pub published: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,7 @@ impl InstanceWorker {
|
||||||
|
|
||||||
// Activity send successful, mark instance as alive if it hasn't been updated in a while.
|
// 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);
|
let updated = self.target.updated.unwrap_or(self.target.published);
|
||||||
|
dbg!(&updated);
|
||||||
if updated.add(Days::new(1)) < Utc::now() {
|
if updated.add(Days::new(1)) < Utc::now() {
|
||||||
self.target.updated = Some(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?;
|
let sent = send_activity(data.person.actor_id.clone(), &data.context).await?;
|
||||||
|
|
||||||
sleep(WORK_FINISHED_RECHECK_DELAY * 2).await;
|
|
||||||
|
|
||||||
// receive for successfully sent activity
|
// receive for successfully sent activity
|
||||||
let inbox_rcv = data.inbox_receiver.recv().await.unwrap();
|
let inbox_rcv = data.inbox_receiver.recv().await.unwrap();
|
||||||
let parsed_activity = serde_json::from_str::<WithContext<Value>>(&inbox_rcv)?;
|
let parsed_activity = serde_json::from_str::<WithContext<Value>>(&inbox_rcv)?;
|
||||||
|
@ -377,6 +376,32 @@ mod test {
|
||||||
Ok(())
|
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(
|
async fn listen_activities(
|
||||||
inbox_sender: UnboundedSender<String>,
|
inbox_sender: UnboundedSender<String>,
|
||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
|
@ -418,6 +443,10 @@ mod test {
|
||||||
actor_type: ActorType::Person,
|
actor_type: ActorType::Person,
|
||||||
actor_apub_id: actor_id,
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue