Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorgan committed Jan 4, 2025
1 parent fc699ba commit 3176e2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion core/src/raw/chrono_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub fn parse_datetime_from_from_timestamp(s: i64) -> Result<DateTime<Utc>> {

/// format datetime into http date, this format is required by:
/// https://httpwg.org/specs/rfc9110.html#field.if-modified-since
///
pub fn format_datetime_into_http_date(s: DateTime<Utc>) -> String {
s.format("%a, %d %b %Y %H:%M:%S GMT").to_string()
}
Expand Down
28 changes: 16 additions & 12 deletions core/tests/behavior/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,16 @@ pub async fn test_reader_with_if_modified_since(op: Operator) -> anyhow::Result<
op.write(&path, content.clone())
.await
.expect("write must succeed");
let last_modified_time = op.stat(&path).await?.last_modified().unwrap();

let since = chrono::Utc::now() - chrono::Duration::seconds(3600);
let since = last_modified_time - chrono::Duration::seconds(1);
let reader = op.reader_with(&path).if_modified_since(since).await?;
let bs = reader.read(..).await?.to_bytes();
assert_eq!(bs, content);

sleep(Duration::from_secs(3)).await;
sleep(Duration::from_secs(1)).await;

let since = chrono::Utc::now() - chrono::Duration::seconds(1);
let since = last_modified_time + chrono::Duration::seconds(1);
let reader = op.reader_with(&path).if_modified_since(since).await?;
let res = reader.read(..).await;
assert!(res.is_err());
Expand All @@ -313,16 +314,17 @@ pub async fn test_reader_with_if_unmodified_since(op: Operator) -> anyhow::Resul
op.write(&path, content.clone())
.await
.expect("write must succeed");
let last_modified_time = op.stat(&path).await?.last_modified().unwrap();

let since = chrono::Utc::now() - chrono::Duration::seconds(3600);
let since = last_modified_time - chrono::Duration::seconds(1);
let reader = op.reader_with(&path).if_unmodified_since(since).await?;
let res = reader.read(..).await;
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind(), ErrorKind::ConditionNotMatch);

sleep(Duration::from_secs(3)).await;
sleep(Duration::from_secs(1)).await;

let since = chrono::Utc::now() - chrono::Duration::seconds(1);
let since = last_modified_time + chrono::Duration::seconds(1);
let reader = op.reader_with(&path).if_unmodified_since(since).await?;
let bs = reader.read(..).await?.to_bytes();
assert_eq!(bs, content);
Expand Down Expand Up @@ -563,18 +565,19 @@ pub async fn test_read_with_if_modified_since(op: Operator) -> anyhow::Result<()
op.write(&path, content.clone())
.await
.expect("write must succeed");
let last_modified_time = op.stat(&path).await?.last_modified().unwrap();

let since = chrono::Utc::now() - chrono::Duration::seconds(3600);
let since = last_modified_time - chrono::Duration::seconds(1);
let bs = op
.read_with(&path)
.if_modified_since(since)
.await?
.to_bytes();
assert_eq!(bs, content);

sleep(Duration::from_secs(3)).await;
sleep(Duration::from_secs(1)).await;

let since = chrono::Utc::now() - chrono::Duration::seconds(1);
let since = last_modified_time + chrono::Duration::seconds(1);
let res = op.read_with(&path).if_modified_since(since).await;
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind(), ErrorKind::ConditionNotMatch);
Expand All @@ -593,15 +596,16 @@ pub async fn test_read_with_if_unmodified_since(op: Operator) -> anyhow::Result<
op.write(&path, content.clone())
.await
.expect("write must succeed");
let last_modified = op.stat(&path).await?.last_modified().unwrap();

let since = chrono::Utc::now() - chrono::Duration::seconds(3600);
let since = last_modified - chrono::Duration::seconds(3600);
let res = op.read_with(&path).if_unmodified_since(since).await;
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind(), ErrorKind::ConditionNotMatch);

sleep(Duration::from_secs(3)).await;
sleep(Duration::from_secs(1)).await;

let since = chrono::Utc::now() - chrono::Duration::seconds(1);
let since = last_modified + chrono::Duration::seconds(1);
let bs = op
.read_with(&path)
.if_unmodified_since(since)
Expand Down

0 comments on commit 3176e2d

Please sign in to comment.