]> Untitled Git - lemmy.git/commitdiff
send activities sync for tests
authorFelix Ableitner <me@nutomic.com>
Mon, 14 Dec 2020 16:44:27 +0000 (17:44 +0100)
committerFelix Ableitner <me@nutomic.com>
Mon, 14 Dec 2020 16:44:27 +0000 (17:44 +0100)
api_tests/prepare-drone-federation-test.sh
api_tests/src/shared.ts
docker/federation/docker-compose.yml
lemmy_apub/src/activity_queue.rs

index 97a5313b526bc74203135605c5523b38c64d65f8..4010eff6614de439c5ca439125497496cace4a27 100755 (executable)
@@ -8,6 +8,7 @@ export LEMMY_SETUP__ADMIN_PASSWORD=lemmy
 export LEMMY_RATE_LIMIT__POST=99999
 export LEMMY_RATE_LIMIT__REGISTER=99999
 export LEMMY_CAPTCHA__ENABLED=false
+export LEMMY_TEST_SEND_SYNC=1
 export RUST_BACKTRACE=1
 
 for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
index ed4899f8e4b14efcf7072d2c026c13a23e3c0343..be6b53adf7f01d7af0c9878b57d7f1422cb091e3 100644 (file)
@@ -615,7 +615,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
 
 export function delay(millis: number = 500) {
   return new Promise((resolve, _reject) => {
-    setTimeout(_ => resolve(), millis);
+    setTimeout(_ => resolve(), 10);
   });
 }
 
index e32dfe2da7751935dff09a18c515438eda5f8536..dc015a2896d3a82e0bcbbc1fd01c02da8cb63f44 100644 (file)
@@ -52,6 +52,7 @@ services:
       - LEMMY_RATE_LIMIT__POST=99999
       - LEMMY_RATE_LIMIT__REGISTER=99999
       - LEMMY_CAPTCHA__ENABLED=false
+      - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
       - RUST_LOG=debug
     depends_on:
@@ -91,6 +92,7 @@ services:
       - LEMMY_RATE_LIMIT__POST=99999
       - LEMMY_RATE_LIMIT__REGISTER=99999
       - LEMMY_CAPTCHA__ENABLED=false
+      - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
       - RUST_LOG=debug
     depends_on:
@@ -130,6 +132,7 @@ services:
       - LEMMY_RATE_LIMIT__POST=99999
       - LEMMY_RATE_LIMIT__REGISTER=99999
       - LEMMY_CAPTCHA__ENABLED=false
+      - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
       - RUST_LOG=debug
     depends_on:
@@ -170,6 +173,7 @@ services:
       - LEMMY_RATE_LIMIT__POST=99999
       - LEMMY_RATE_LIMIT__REGISTER=99999
       - LEMMY_CAPTCHA__ENABLED=false
+      - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
       - RUST_LOG=debug
     depends_on:
@@ -210,6 +214,7 @@ services:
       - LEMMY_RATE_LIMIT__POST=99999
       - LEMMY_RATE_LIMIT__REGISTER=99999
       - LEMMY_CAPTCHA__ENABLED=false
+      - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
       - RUST_LOG=debug
     depends_on:
index 5e4f113b5dc0fd9c5c98386c8b9676bb2a2af095..1b5ffb937a2ec3c3f7274aa5bc16df1c2950bf20 100644 (file)
@@ -25,7 +25,7 @@ use lemmy_websocket::LemmyContext;
 use log::{debug, warn};
 use reqwest::Client;
 use serde::{export::fmt::Debug, Deserialize, Serialize};
-use std::{collections::BTreeMap, future::Future, pin::Pin};
+use std::{collections::BTreeMap, future::Future, pin::Pin, env};
 use url::Url;
 
 /// Sends a local activity to a single, remote actor.
@@ -234,7 +234,11 @@ where
       actor_id: actor.actor_id()?,
       private_key: actor.private_key().context(location_info!())?,
     };
-    activity_sender.queue::<SendActivityTask>(message)?;
+    if env::var("LEMMY_TEST_SEND_SYNC").is_ok() {
+      do_send(message, &Client::default()).await?;
+    } else {
+      activity_sender.queue::<SendActivityTask>(message)?;
+    }
   }
 
   Ok(())
@@ -260,29 +264,33 @@ impl ActixJob for SendActivityTask {
 
   fn run(self, state: Self::State) -> Self::Future {
     Box::pin(async move {
-      let mut headers = BTreeMap::<String, String>::new();
-      headers.insert("Content-Type".into(), "application/json".into());
-      let result = sign_and_send(
-        &state.client,
-        headers,
-        &self.inbox,
-        self.activity.clone(),
-        &self.actor_id,
-        self.private_key.to_owned(),
-      )
-      .await;
+      do_send(self, &state.client).await
+    })
+  }
+}
 
-      if let Err(e) = result {
-        warn!("{}", e);
-        return Err(anyhow!(
+async fn do_send(task: SendActivityTask, client: &Client) -> Result<(), Error>{
+  let mut headers = BTreeMap::<String, String>::new();
+  headers.insert("Content-Type".into(), "application/json".into());
+  let result = sign_and_send(
+    client,
+    headers,
+    &task.inbox,
+    task.activity.clone(),
+    &task.actor_id,
+    task.private_key.to_owned(),
+  )
+    .await;
+
+  if let Err(e) = result {
+    warn!("{}", e);
+    return Err(anyhow!(
           "Failed to send activity {} to {}",
-          &self.activity,
-          self.inbox
+          &task.activity,
+          task.inbox
         ));
-      }
-      Ok(())
-    })
   }
+  Ok(())
 }
 
 pub fn create_activity_queue() -> QueueHandle {