mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-04 11:46:30 +00:00
Fix tests
This commit is contained in:
@ -820,6 +820,7 @@ impl IndexScheduler {
|
||||
|
||||
let rtxn = self.env.read_txn()?;
|
||||
|
||||
for (uuid, Webhook { url, headers }) in webhooks.webhooks.iter() {
|
||||
let task_reader = TaskReader {
|
||||
rtxn: &rtxn,
|
||||
index_scheduler: self,
|
||||
@ -828,50 +829,8 @@ impl IndexScheduler {
|
||||
written: 0,
|
||||
};
|
||||
|
||||
enum EitherRead<'a, T: Read> {
|
||||
Other(Option<T>),
|
||||
Data(&'a [u8]),
|
||||
}
|
||||
let reader = GzEncoder::new(BufReader::new(task_reader), Compression::default());
|
||||
|
||||
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() {
|
||||
let mut request = ureq::post(url)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.set("Content-Encoding", "gzip")
|
||||
@ -880,7 +839,7 @@ impl IndexScheduler {
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,6 @@ async fn cli_only() {
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
#[ignore = "Broken"]
|
||||
async fn single_receives_data() {
|
||||
let WebhookHandle { server_handle, url, mut receiver } = create_webhook_server().await;
|
||||
|
||||
@ -166,7 +165,6 @@ async fn single_receives_data() {
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
#[ignore = "Broken"]
|
||||
async fn multiple_receive_data() {
|
||||
let server = Server::new().await;
|
||||
|
||||
|
Reference in New Issue
Block a user