From 5a770ffe474a02c0d2888cea350613109ceeecdd Mon Sep 17 00:00:00 2001 From: jiangbo212 Date: Sat, 3 Dec 2022 22:48:38 +0800 Subject: [PATCH] test fail fix --- index-scheduler/src/lib.rs | 2 +- meilisearch-http/src/routes/indexes/documents.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 8fafd99d9..a7dab68d1 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -1193,7 +1193,7 @@ mod tests { ) -> std::result::Result { let temp_file = NamedTempFile::new().unwrap(); let mut buffer = BufWriter::new(temp_file.reopen().unwrap()); - buffer.write(bytes).unwrap(); + buffer.write_all(bytes).unwrap(); buffer.flush().unwrap(); meilisearch_types::document_formats::read_json(temp_file.as_file(), write) } diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index 821361814..c10d15e81 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -29,7 +29,7 @@ use serde_json::Value; use std::io::ErrorKind; use tempfile::NamedTempFile; use tokio::fs::File; -use tokio::io::{AsyncWriteExt, BufWriter}; +use tokio::io::AsyncWriteExt; static ACCEPTED_CONTENT_TYPE: Lazy> = Lazy::new(|| { vec!["application/json".to_string(), "application/x-ndjson".to_string(), "text/csv".to_string()] @@ -244,16 +244,22 @@ async fn document_addition( return Err(MeilisearchHttpError::Payload(ReceivePayloadErr)); } }; - let mut buffer = BufWriter::new(File::from_std(buffer_file)); + let mut buffer = File::from_std(buffer_file); let mut buffer_write_size: usize = 0; while let Some(bytes) = body.next().await { - match buffer.write(&bytes?).await { - Ok(size) => buffer_write_size += size, + let byte = &bytes?; + + if byte.is_empty() && buffer_write_size == 0 { + return Err(MeilisearchHttpError::MissingPayload(format)); + } + + match buffer.write_all(byte).await { + Ok(()) => buffer_write_size += 1, Err(e) => { error!("bufWriter write error: {}", e); return Err(MeilisearchHttpError::Payload(ReceivePayloadErr)); } - } + }; } if let Err(e) = buffer.flush().await {