mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
fix(all): fix two dates that were wrongly formatted
This commit is contained in:
parent
c3e3c900f2
commit
21d277a0ef
@ -1,4 +1,5 @@
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||||
|
|
||||||
use crate::common::Server;
|
use crate::common::Server;
|
||||||
|
|
||||||
@ -57,11 +58,15 @@ async fn stats() {
|
|||||||
|
|
||||||
index.wait_task(1).await;
|
index.wait_task(1).await;
|
||||||
|
|
||||||
|
let timestamp = OffsetDateTime::now_utc();
|
||||||
let (response, code) = server.stats().await;
|
let (response, code) = server.stats().await;
|
||||||
|
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
assert!(response["databaseSize"].as_u64().unwrap() > 0);
|
assert!(response["databaseSize"].as_u64().unwrap() > 0);
|
||||||
assert!(response.get("lastUpdate").is_some());
|
let last_update =
|
||||||
|
OffsetDateTime::parse(response["lastUpdate"].as_str().unwrap(), &Rfc3339).unwrap();
|
||||||
|
assert!(last_update - timestamp < time::Duration::SECOND);
|
||||||
|
|
||||||
assert_eq!(response["indexes"]["test"]["numberOfDocuments"], 2);
|
assert_eq!(response["indexes"]["test"]["numberOfDocuments"], 2);
|
||||||
assert!(response["indexes"]["test"]["isIndexing"] == false);
|
assert!(response["indexes"]["test"]["isIndexing"] == false);
|
||||||
assert_eq!(response["indexes"]["test"]["fieldDistribution"]["id"], 2);
|
assert_eq!(response["indexes"]["test"]["fieldDistribution"]["id"], 2);
|
||||||
|
@ -31,7 +31,9 @@ pub struct DumpActor {
|
|||||||
/// Generate uid from creation date
|
/// Generate uid from creation date
|
||||||
fn generate_uid() -> String {
|
fn generate_uid() -> String {
|
||||||
OffsetDateTime::now_utc()
|
OffsetDateTime::now_utc()
|
||||||
.format(format_description!("%Y%m%d-%H%M%S%3f"))
|
.format(format_description!(
|
||||||
|
"[year repr:full][month repr:numerical][day padding:zero]-[hour padding:zero][minute padding:zero][second padding:zero][subsecond digits:3]"
|
||||||
|
))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,3 +159,33 @@ impl DumpActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_generate_uid() {
|
||||||
|
let current = OffsetDateTime::now_utc();
|
||||||
|
|
||||||
|
let uid = generate_uid();
|
||||||
|
let (date, time) = uid.split_once('-').unwrap();
|
||||||
|
|
||||||
|
let date = time::Date::parse(
|
||||||
|
date,
|
||||||
|
&format_description!("[year repr:full][month repr:numerical][day padding:zero]"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let time = time::Time::parse(
|
||||||
|
time,
|
||||||
|
&format_description!(
|
||||||
|
"[hour padding:zero][minute padding:zero][second padding:zero][subsecond digits:3]"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let datetime = time::PrimitiveDateTime::new(date, time);
|
||||||
|
let datetime = datetime.assume_utc();
|
||||||
|
|
||||||
|
assert!(current - datetime < time::Duration::SECOND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -107,6 +107,7 @@ impl fmt::Display for DocumentAdditionFormat {
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Stats {
|
pub struct Stats {
|
||||||
pub database_size: u64,
|
pub database_size: u64,
|
||||||
|
#[serde(serialize_with = "time::serde::rfc3339::option::serialize")]
|
||||||
pub last_update: Option<OffsetDateTime>,
|
pub last_update: Option<OffsetDateTime>,
|
||||||
pub indexes: BTreeMap<String, IndexStats>,
|
pub indexes: BTreeMap<String, IndexStats>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user