Skip to content

Commit 7182a4f

Browse files
committed
Sort out tokio tests
1 parent e61a410 commit 7182a4f

File tree

5 files changed

+83
-46
lines changed

5 files changed

+83
-46
lines changed

s3/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ bytes = { version = "1.2" }
9292
block_on_proc = { version = "0.2", optional = true }
9393

9494
[features]
95-
default = ["tags", "use-tokio-native-tls", "fail-on-err"]
95+
default = ["tokio-rustls-tls"]
96+
# default = ["tags", "use-tokio-native-tls", "fail-on-err"]
9697
use-tokio-native-tls = [
9798
"with-tokio",
9899
"aws-creds/native-tls",

s3/src/bucket.rs

+62-41
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use crate::bucket_ops::{BucketConfiguration, CreateBucketResponse};
99
use crate::command::{Command, Multipart};
1010
use crate::creds::Credentials;
1111
use crate::region::Region;
12-
#[cfg(feature = "with-tokio")]
13-
use crate::request::tokio_backend::{client, HttpsConnector};
12+
#[cfg(any(feature = "with-tokio", feature = "use-tokio-native-tls"))]
13+
use crate::request::tokio_backend::client;
14+
#[cfg(any(feature = "use-tokio-native-tls", feature = "tokio-rustls-tls"))]
15+
use crate::request::tokio_backend::HttpsConnector;
1416
use crate::request::ResponseData;
1517
#[cfg(any(feature = "with-tokio", feature = "with-async-std"))]
1618
use crate::request::ResponseDataStream;
@@ -106,8 +108,14 @@ pub struct Bucket {
106108
pub request_timeout: Option<Duration>,
107109
path_style: bool,
108110
listobjects_v2: bool,
109-
#[cfg(feature = "with-tokio")]
111+
#[cfg(any(feature = "use-tokio-native-tls", feature = "tokio-rustls-tls"))]
110112
http_client: Arc<hyper::Client<HttpsConnector<hyper::client::HttpConnector>>>,
113+
#[cfg(all(
114+
feature = "with-tokio",
115+
not(feature = "use-tokio-native-tls"),
116+
not(feature = "tokio-rustls-tls")
117+
))]
118+
http_client: Arc<hyper::Client<hyper::client::HttpConnector>>,
111119
}
112120

113121
impl Bucket {
@@ -126,7 +134,16 @@ impl Bucket {
126134
}
127135
}
128136

129-
#[cfg(feature = "with-tokio")]
137+
#[cfg(all(
138+
feature = "with-tokio",
139+
not(feature = "use-tokio-native-tls"),
140+
not(feature = "tokio-rustls-tls")
141+
))]
142+
pub fn http_client(&self) -> Arc<hyper::Client<hyper::client::HttpConnector>> {
143+
Arc::clone(&self.http_client)
144+
}
145+
146+
#[cfg(any(feature = "use-tokio-native-tls", feature = "tokio-rustls-tls"))]
130147
pub fn http_client(&self) -> Arc<hyper::Client<HttpsConnector<hyper::client::HttpConnector>>> {
131148
Arc::clone(&self.http_client)
132149
}
@@ -224,7 +241,7 @@ impl Bucket {
224241
&self,
225242
post_policy: PostPolicy<'a>,
226243
) -> Result<PresignedPost, S3Error> {
227-
post_policy.sign(self.clone()).await
244+
post_policy.sign(Box::new(self.clone())).await
228245
}
229246

230247
/// Get a presigned url for putting object to a given path
@@ -557,8 +574,12 @@ impl Bucket {
557574
///
558575
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
559576
/// ```
560-
pub fn new(name: &str, region: Region, credentials: Credentials) -> Result<Bucket, S3Error> {
561-
Ok(Bucket {
577+
pub fn new(
578+
name: &str,
579+
region: Region,
580+
credentials: Credentials,
581+
) -> Result<Box<Bucket>, S3Error> {
582+
Ok(Box::new(Bucket {
562583
name: name.into(),
563584
region,
564585
credentials: Arc::new(RwLock::new(credentials)),
@@ -567,9 +588,9 @@ impl Bucket {
567588
request_timeout: DEFAULT_REQUEST_TIMEOUT,
568589
path_style: false,
569590
listobjects_v2: true,
570-
#[cfg(feature = "with-tokio")]
591+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
571592
http_client: Arc::new(client(DEFAULT_REQUEST_TIMEOUT)?),
572-
})
593+
}))
573594
}
574595

575596
/// Instantiate a public existing `Bucket`.
@@ -593,13 +614,13 @@ impl Bucket {
593614
request_timeout: DEFAULT_REQUEST_TIMEOUT,
594615
path_style: false,
595616
listobjects_v2: true,
596-
#[cfg(feature = "with-tokio")]
617+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
597618
http_client: Arc::new(client(DEFAULT_REQUEST_TIMEOUT)?),
598619
})
599620
}
600621

601-
pub fn with_path_style(&self) -> Bucket {
602-
Bucket {
622+
pub fn with_path_style(&self) -> Box<Bucket> {
623+
Box::new(Bucket {
603624
name: self.name.clone(),
604625
region: self.region.clone(),
605626
credentials: self.credentials.clone(),
@@ -608,9 +629,9 @@ impl Bucket {
608629
request_timeout: self.request_timeout,
609630
path_style: true,
610631
listobjects_v2: self.listobjects_v2,
611-
#[cfg(feature = "with-tokio")]
632+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
612633
http_client: self.http_client.clone(),
613-
}
634+
})
614635
}
615636

616637
pub fn with_extra_headers(&self, extra_headers: HeaderMap) -> Result<Bucket, S3Error> {
@@ -623,7 +644,7 @@ impl Bucket {
623644
request_timeout: self.request_timeout,
624645
path_style: self.path_style,
625646
listobjects_v2: self.listobjects_v2,
626-
#[cfg(feature = "with-tokio")]
647+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
627648
http_client: self.http_client.clone(),
628649
})
629650
}
@@ -641,13 +662,13 @@ impl Bucket {
641662
request_timeout: self.request_timeout,
642663
path_style: self.path_style,
643664
listobjects_v2: self.listobjects_v2,
644-
#[cfg(feature = "with-tokio")]
665+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
645666
http_client: self.http_client.clone(),
646667
})
647668
}
648669

649-
pub fn with_request_timeout(&self, request_timeout: Duration) -> Result<Bucket, S3Error> {
650-
Ok(Bucket {
670+
pub fn with_request_timeout(&self, request_timeout: Duration) -> Result<Box<Bucket>, S3Error> {
671+
Ok(Box::new(Bucket {
651672
name: self.name.clone(),
652673
region: self.region.clone(),
653674
credentials: self.credentials.clone(),
@@ -656,9 +677,9 @@ impl Bucket {
656677
request_timeout: Some(request_timeout),
657678
path_style: self.path_style,
658679
listobjects_v2: self.listobjects_v2,
659-
#[cfg(feature = "with-tokio")]
680+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
660681
http_client: Arc::new(client(Some(request_timeout))?),
661-
})
682+
}))
662683
}
663684

664685
pub fn with_listobjects_v1(&self) -> Bucket {
@@ -671,7 +692,7 @@ impl Bucket {
671692
request_timeout: self.request_timeout,
672693
path_style: self.path_style,
673694
listobjects_v2: false,
674-
#[cfg(feature = "with-tokio")]
695+
#[cfg(any(feature = "use-tokio-native-tls", feature = "with-tokio"))]
675696
http_client: self.http_client.clone(),
676697
}
677698
}
@@ -2492,7 +2513,7 @@ mod test {
24922513
.unwrap()
24932514
}
24942515

2495-
fn test_aws_bucket() -> Bucket {
2516+
fn test_aws_bucket() -> Box<Bucket> {
24962517
Bucket::new(
24972518
"rust-s3-test",
24982519
"eu-central-1".parse().unwrap(),
@@ -2501,7 +2522,7 @@ mod test {
25012522
.unwrap()
25022523
}
25032524

2504-
fn test_wasabi_bucket() -> Bucket {
2525+
fn test_wasabi_bucket() -> Box<Bucket> {
25052526
Bucket::new(
25062527
"rust-s3",
25072528
"wa-eu-central-1".parse().unwrap(),
@@ -2510,7 +2531,7 @@ mod test {
25102531
.unwrap()
25112532
}
25122533

2513-
fn test_gc_bucket() -> Bucket {
2534+
fn test_gc_bucket() -> Box<Bucket> {
25142535
let mut bucket = Bucket::new(
25152536
"rust-s3",
25162537
Region::Custom {
@@ -2524,7 +2545,7 @@ mod test {
25242545
bucket
25252546
}
25262547

2527-
fn test_minio_bucket() -> Bucket {
2548+
fn test_minio_bucket() -> Box<Bucket> {
25282549
Bucket::new(
25292550
"rust-s3",
25302551
Region::Custom {
@@ -2538,11 +2559,11 @@ mod test {
25382559
}
25392560

25402561
#[allow(dead_code)]
2541-
fn test_digital_ocean_bucket() -> Bucket {
2562+
fn test_digital_ocean_bucket() -> Box<Bucket> {
25422563
Bucket::new("rust-s3", Region::DoFra1, test_digital_ocean_credentials()).unwrap()
25432564
}
25442565

2545-
fn test_r2_bucket() -> Bucket {
2566+
fn test_r2_bucket() -> Box<Bucket> {
25462567
Bucket::new(
25472568
"rust-s3",
25482569
Region::R2 {
@@ -2680,7 +2701,7 @@ mod test {
26802701
)
26812702
)]
26822703
async fn streaming_big_aws_put_head_get_delete_object() {
2683-
streaming_test_put_get_delete_big_object(test_aws_bucket()).await;
2704+
streaming_test_put_get_delete_big_object(*test_aws_bucket()).await;
26842705
}
26852706

26862707
#[ignore]
@@ -2700,7 +2721,7 @@ mod test {
27002721
)
27012722
)]
27022723
async fn streaming_big_gc_put_head_get_delete_object() {
2703-
streaming_test_put_get_delete_big_object(test_gc_bucket()).await;
2724+
streaming_test_put_get_delete_big_object(*test_gc_bucket()).await;
27042725
}
27052726

27062727
#[ignore]
@@ -2713,7 +2734,7 @@ mod test {
27132734
)
27142735
)]
27152736
async fn streaming_big_minio_put_head_get_delete_object() {
2716-
streaming_test_put_get_delete_big_object(test_minio_bucket()).await;
2737+
streaming_test_put_get_delete_big_object(*test_minio_bucket()).await;
27172738
}
27182739

27192740
// Test multi-part upload
@@ -2838,7 +2859,7 @@ mod test {
28382859
}
28392860

28402861
#[maybe_async::maybe_async]
2841-
async fn streaming_test_put_get_delete_small_object(bucket: Bucket) {
2862+
async fn streaming_test_put_get_delete_small_object(bucket: Box<Bucket>) {
28422863
init();
28432864
let remote_path = "+stream_test_small";
28442865
let content: Vec<u8> = object(1000);
@@ -2949,7 +2970,7 @@ mod test {
29492970
))]
29502971
#[test]
29512972
fn aws_put_head_get_delete_object_blocking() {
2952-
put_head_get_list_delete_object_blocking(test_aws_bucket())
2973+
put_head_get_list_delete_object_blocking(*test_aws_bucket())
29532974
}
29542975

29552976
#[ignore]
@@ -2959,7 +2980,7 @@ mod test {
29592980
))]
29602981
#[test]
29612982
fn gc_put_head_get_delete_object_blocking() {
2962-
put_head_get_list_delete_object_blocking(test_gc_bucket())
2983+
put_head_get_list_delete_object_blocking(*test_gc_bucket())
29632984
}
29642985

29652986
#[ignore]
@@ -2969,7 +2990,7 @@ mod test {
29692990
))]
29702991
#[test]
29712992
fn wasabi_put_head_get_delete_object_blocking() {
2972-
put_head_get_list_delete_object_blocking(test_wasabi_bucket())
2993+
put_head_get_list_delete_object_blocking(*test_wasabi_bucket())
29732994
}
29742995

29752996
#[ignore]
@@ -2979,7 +3000,7 @@ mod test {
29793000
))]
29803001
#[test]
29813002
fn minio_put_head_get_delete_object_blocking() {
2982-
put_head_get_list_delete_object_blocking(test_minio_bucket())
3003+
put_head_get_list_delete_object_blocking(*test_minio_bucket())
29833004
}
29843005

29853006
#[ignore]
@@ -2989,7 +3010,7 @@ mod test {
29893010
))]
29903011
#[test]
29913012
fn digital_ocean_put_head_get_delete_object_blocking() {
2992-
put_head_get_list_delete_object_blocking(test_digital_ocean_bucket())
3013+
put_head_get_list_delete_object_blocking(*test_digital_ocean_bucket())
29933014
}
29943015

29953016
#[ignore]
@@ -3002,7 +3023,7 @@ mod test {
30023023
)
30033024
)]
30043025
async fn aws_put_head_get_delete_object() {
3005-
put_head_get_delete_object(test_aws_bucket(), true).await;
3026+
put_head_get_delete_object(*test_aws_bucket(), true).await;
30063027
}
30073028

30083029
#[ignore]
@@ -3021,7 +3042,7 @@ mod test {
30213042
)
30223043
)]
30233044
async fn gc_test_put_head_get_delete_object() {
3024-
put_head_get_delete_object(test_gc_bucket(), true).await;
3045+
put_head_get_delete_object(*test_gc_bucket(), true).await;
30253046
}
30263047

30273048
#[ignore]
@@ -3034,7 +3055,7 @@ mod test {
30343055
)
30353056
)]
30363057
async fn wasabi_test_put_head_get_delete_object() {
3037-
put_head_get_delete_object(test_wasabi_bucket(), true).await;
3058+
put_head_get_delete_object(*test_wasabi_bucket(), true).await;
30383059
}
30393060

30403061
#[ignore]
@@ -3047,7 +3068,7 @@ mod test {
30473068
)
30483069
)]
30493070
async fn minio_test_put_head_get_delete_object() {
3050-
put_head_get_delete_object(test_minio_bucket(), true).await;
3071+
put_head_get_delete_object(*test_minio_bucket(), true).await;
30513072
}
30523073

30533074
// Keeps failing on tokio-rustls-tls
@@ -3074,7 +3095,7 @@ mod test {
30743095
)
30753096
)]
30763097
async fn r2_test_put_head_get_delete_object() {
3077-
put_head_get_delete_object(test_r2_bucket(), false).await;
3098+
put_head_get_delete_object(*test_r2_bucket(), false).await;
30783099
}
30793100

30803101
#[maybe_async::test(

s3/src/bucket_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl BucketConfiguration {
194194

195195
#[allow(dead_code)]
196196
pub struct CreateBucketResponse {
197-
pub bucket: Bucket,
197+
pub bucket: Box<Bucket>,
198198
pub response_text: String,
199199
pub response_code: u16,
200200
}

s3/src/post_policy.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a> PostPolicy<'a> {
7878
}
7979

8080
#[maybe_async::maybe_async]
81-
pub async fn sign(&self, bucket: Bucket) -> Result<PresignedPost, S3Error> {
81+
pub async fn sign(&self, bucket: Box<Bucket>) -> Result<PresignedPost, S3Error> {
8282
use hmac::Mac;
8383

8484
bucket.credentials_refresh().await?;
@@ -429,7 +429,7 @@ mod test {
429429

430430
use serde_json::json;
431431

432-
fn test_bucket() -> Bucket {
432+
fn test_bucket() -> Box<Bucket> {
433433
Bucket::new(
434434
"rust-s3",
435435
Region::UsEast1,
@@ -445,7 +445,7 @@ mod test {
445445
.unwrap()
446446
}
447447

448-
fn test_bucket_with_security_token() -> Bucket {
448+
fn test_bucket_with_security_token() -> Box<Bucket> {
449449
Bucket::new(
450450
"rust-s3",
451451
Region::UsEast1,

0 commit comments

Comments
 (0)