test cleanup

This commit is contained in:
Felix Ableitner 2024-03-01 11:12:48 +01:00
parent 3ea4bb6e53
commit 8dab05e30c
2 changed files with 9 additions and 27 deletions

View file

@ -3,10 +3,9 @@
#![doc = include_str!("../docs/09_sending_activities.md")] #![doc = include_str!("../docs/09_sending_activities.md")]
use crate::{ use crate::{
activity_sending::{build_tasks, generate_request_headers, SendActivityTask}, activity_sending::{build_tasks, SendActivityTask},
config::Data, config::Data,
error::Error, error::Error,
http_signatures::sign_request,
traits::{ActivityHandler, Actor}, traits::{ActivityHandler, Actor},
}; };
@ -26,7 +25,7 @@ use tokio::{
sync::mpsc::{unbounded_channel, UnboundedSender}, sync::mpsc::{unbounded_channel, UnboundedSender},
task::{JoinHandle, JoinSet}, task::{JoinHandle, JoinSet},
}; };
use tracing::{debug, info, warn}; use tracing::{info, warn};
use url::Url; use url::Url;
/// Send a new activity to the given inboxes with automatic retry on failure. Alternatively you /// Send a new activity to the given inboxes with automatic retry on failure. Alternatively you
@ -418,16 +417,14 @@ async fn retry<T, E: Display + Debug, F: Future<Output = Result<T, E>>, A: FnMut
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use crate::http_signatures::generate_actor_keypair;
use axum::extract::State; use axum::extract::State;
use bytes::Bytes; use bytes::Bytes;
use http::{HeaderMap, StatusCode}; use http::{HeaderMap, StatusCode};
use std::time::Instant; use std::time::Instant;
use tracing::debug;
use crate::http_signatures::generate_actor_keypair;
use super::*;
#[allow(unused)]
// This will periodically send back internal errors to test the retry // This will periodically send back internal errors to test the retry
async fn dodgy_handler( async fn dodgy_handler(
State(state): State<Arc<AtomicUsize>>, State(state): State<Arc<AtomicUsize>>,

View file

@ -15,10 +15,7 @@ use futures::StreamExt;
use httpdate::fmt_http_date; use httpdate::fmt_http_date;
use itertools::Itertools; use itertools::Itertools;
use openssl::pkey::{PKey, Private}; use openssl::pkey::{PKey, Private};
use reqwest::{ use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
header::{HeaderMap, HeaderName, HeaderValue},
Request,
};
use reqwest_middleware::ClientWithMiddleware; use reqwest_middleware::ClientWithMiddleware;
use serde::Serialize; use serde::Serialize;
use std::{ use std::{
@ -221,7 +218,8 @@ pub(crate) fn generate_request_headers(inbox_url: &Url) -> HeaderMap {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use axum::extract::State; use super::*;
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
use bytes::Bytes; use bytes::Bytes;
use http::StatusCode; use http::StatusCode;
use std::{ use std::{
@ -230,23 +228,10 @@ mod tests {
}; };
use tracing::info; use tracing::info;
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
use super::*;
#[allow(unused)]
// This will periodically send back internal errors to test the retry // This will periodically send back internal errors to test the retry
async fn dodgy_handler( async fn dodgy_handler(headers: HeaderMap, body: Bytes) -> Result<(), StatusCode> {
State(state): State<Arc<AtomicUsize>>,
headers: HeaderMap,
body: Bytes,
) -> Result<(), StatusCode> {
debug!("Headers:{:?}", headers); debug!("Headers:{:?}", headers);
debug!("Body len:{}", body.len()); debug!("Body len:{}", body.len());
/*if state.fetch_add(1, Ordering::Relaxed) % 20 == 0 {
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}*/
Ok(()) Ok(())
} }