You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/02/21 02:04:42 UTC
(opendal) branch add-test-for-timeout created (now 33eeb7efd5)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a change to branch add-test-for-timeout
in repository https://gitbox.apache.org/repos/asf/opendal.git
at 33eeb7efd5 feat(test): Cover the test for list timeout
This branch includes the following new commits:
new 33eeb7efd5 feat(test): Cover the test for list timeout
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(opendal) 01/01: feat(test): Cover the test for list timeout
Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch add-test-for-timeout
in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 33eeb7efd5d425081964ad93a2013dc07b44e2a3
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Feb 21 10:04:20 2024 +0800
feat(test): Cover the test for list timeout
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
core/src/layers/timeout.rs | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/core/src/layers/timeout.rs b/core/src/layers/timeout.rs
index 4eec45bd87..5812b79a4a 100644
--- a/core/src/layers/timeout.rs
+++ b/core/src/layers/timeout.rs
@@ -380,6 +380,7 @@ mod tests {
use async_trait::async_trait;
use bytes::Bytes;
+ use futures::StreamExt;
use tokio::time::sleep;
use tokio::time::timeout;
@@ -397,7 +398,7 @@ mod tests {
impl Accessor for MockService {
type Reader = MockReader;
type Writer = ();
- type Lister = ();
+ type Lister = MockLister;
type BlockingReader = ();
type BlockingWriter = ();
type BlockingLister = ();
@@ -424,6 +425,10 @@ mod tests {
Ok(RpDelete::default())
}
+
+ async fn list(&self, _: &str, _: OpList) -> Result<(RpList, Self::Lister)> {
+ Ok((RpList::default(), MockLister))
+ }
}
#[derive(Debug, Clone, Default)]
@@ -443,6 +448,15 @@ mod tests {
}
}
+ #[derive(Debug, Clone, Default)]
+ struct MockLister;
+
+ impl oio::List for MockLister {
+ fn poll_next(&mut self, _: &mut Context<'_>) -> Poll<Result<Option<oio::Entry>>> {
+ Poll::Pending
+ }
+ }
+
#[tokio::test]
async fn test_operation_timeout() {
let acc = Arc::new(TypeEraseLayer.layer(MockService)) as FusedAccessor;
@@ -482,4 +496,28 @@ mod tests {
.await
.expect("this test should not exceed 2 seconds")
}
+
+ #[tokio::test]
+ async fn test_list_timeout() {
+ let acc = Arc::new(TypeEraseLayer.layer(MockService)) as FusedAccessor;
+ let op = Operator::from_inner(acc).layer(
+ TimeoutLayer::new()
+ .with_timeout(Duration::from_secs(1))
+ .with_io_timeout(Duration::from_secs(1)),
+ );
+
+ let fut = async {
+ let mut lister = op.lister("test").await.unwrap();
+
+ let res = lister.next().await.unwrap();
+ assert!(res.is_err());
+ let err = res.unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::Unexpected);
+ assert!(err.to_string().contains("timeout"))
+ };
+
+ timeout(Duration::from_secs(2), fut)
+ .await
+ .expect("this test should not exceed 2 seconds")
+ }
}