Xuanwo commented on code in PR #5500:
URL: https://github.com/apache/opendal/pull/5500#discussion_r1902284752
##########
core/tests/behavior/async_read.rs:
##########
@@ -270,6 +274,74 @@ pub async fn test_reader_with_if_none_match(op: Operator)
-> anyhow::Result<()>
Ok(())
}
+/// Reader with if_modified_since should match, otherwise, a ConditionNotMatch
error will be returned.
+pub async fn test_reader_with_if_modified_since(op: Operator) ->
anyhow::Result<()> {
+ if !op.info().full_capability().read_with_if_modified_since {
+ return Ok(());
+ }
+
+ let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
+
+ op.write(&path, content.clone())
+ .await
+ .expect("write must succeed");
+
+ let one_hour_ago_check = chrono::Utc::now() -
chrono::Duration::seconds(3600);
+ let reader = op
+ .reader_with(&path)
+ .if_modified_since(one_hour_ago_check)
+ .await?;
+ let bs = reader.read(..).await?.to_bytes();
+ assert_eq!(bs, content);
+
+ sleep(Duration::from_secs(3)).await;
+
+ let one_second_ago_check = chrono::Utc::now() -
chrono::Duration::seconds(1);
Review Comment:
Interesting. Ok, let's test in this way:
- Create a file.
- Retrieve its last modified time.
- Read it using `last_modified - 1s` (this should work).
- Wait for 1 second.
- Attempt to read it using `last_modified + 1s` (this should result in an
error).
What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]