Fix tests

This commit is contained in:
Mubelotix
2025-08-04 15:37:12 +02:00
parent 737ad3ec19
commit 8dfebbb3e7
2 changed files with 11 additions and 54 deletions

View File

@ -820,58 +820,17 @@ impl IndexScheduler {
let rtxn = self.env.read_txn()?; let rtxn = self.env.read_txn()?;
let task_reader = TaskReader {
rtxn: &rtxn,
index_scheduler: self,
tasks: &mut updated.into_iter(),
buffer: Vec::with_capacity(800), // on average a task is around ~600 bytes
written: 0,
};
enum EitherRead<'a, T: Read> {
Other(Option<T>),
Data(&'a [u8]),
}
impl<T: Read> EitherRead<'_, T> {
/// A clone that works only once for the Other variant.
fn clone(&mut self) -> Self {
match self {
Self::Other(r) => {
let r = r.take();
Self::Other(r)
}
Self::Data(arg0) => Self::Data(arg0),
}
}
}
impl<T: Read> Read for EitherRead<'_, T> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
match self {
EitherRead::Other(Some(reader)) => reader.read(buf),
EitherRead::Other(None) => {
Err(io::Error::new(io::ErrorKind::Other, "No reader available"))
}
EitherRead::Data(data) => data.read(buf),
}
}
}
let mut reader = GzEncoder::new(BufReader::new(task_reader), Compression::default());
// When there is more than one webhook, cache the data in memory
let mut data;
let mut reader = match webhooks.webhooks.len() {
1 => EitherRead::Other(Some(reader)),
_ => {
data = Vec::new();
reader.read_to_end(&mut data)?;
EitherRead::Data(&data)
}
};
for (uuid, Webhook { url, headers }) in webhooks.webhooks.iter() { for (uuid, Webhook { url, headers }) in webhooks.webhooks.iter() {
let task_reader = TaskReader {
rtxn: &rtxn,
index_scheduler: self,
tasks: &mut updated.into_iter(),
buffer: Vec::with_capacity(800), // on average a task is around ~600 bytes
written: 0,
};
let reader = GzEncoder::new(BufReader::new(task_reader), Compression::default());
let mut request = ureq::post(url) let mut request = ureq::post(url)
.timeout(Duration::from_secs(30)) .timeout(Duration::from_secs(30))
.set("Content-Encoding", "gzip") .set("Content-Encoding", "gzip")
@ -880,7 +839,7 @@ impl IndexScheduler {
request = request.set(header_name, header_value); request = request.set(header_name, header_value);
} }
if let Err(e) = request.send(reader.clone()) { if let Err(e) = request.send(reader) {
tracing::error!("While sending data to the webhook {uuid}: {e}"); tracing::error!("While sending data to the webhook {uuid}: {e}");
} }
} }

View File

@ -99,7 +99,6 @@ async fn cli_only() {
} }
#[actix_web::test] #[actix_web::test]
#[ignore = "Broken"]
async fn single_receives_data() { async fn single_receives_data() {
let WebhookHandle { server_handle, url, mut receiver } = create_webhook_server().await; let WebhookHandle { server_handle, url, mut receiver } = create_webhook_server().await;
@ -166,7 +165,6 @@ async fn single_receives_data() {
} }
#[actix_web::test] #[actix_web::test]
#[ignore = "Broken"]
async fn multiple_receive_data() { async fn multiple_receive_data() {
let server = Server::new().await; let server = Server::new().await;