Skip to content

Commit 0165888

Browse files
committed
Fix test concurrency
1 parent 5514e58 commit 0165888

File tree

5 files changed

+75
-106
lines changed

5 files changed

+75
-106
lines changed

object_store/src/aws/mod.rs

+26-29
Original file line numberDiff line numberDiff line change
@@ -1297,45 +1297,42 @@ mod tests {
12971297
assert!(builder.is_err());
12981298
}
12991299

1300-
#[test]
1301-
fn s3_test_non_tokio() {
1302-
let (handle, shutdown) = dedicated_tokio();
1303-
let config = maybe_skip_integration!();
1304-
let integration = config.with_tokio_runtime(handle).build().unwrap();
1305-
futures::executor::block_on(async move {
1306-
put_get_delete_list_opts(&integration, true).await;
1300+
#[tokio::test]
1301+
async fn s3_test() {
1302+
let builder = maybe_skip_integration!();
1303+
let is_local = matches!(&builder.endpoint, Some(e) if e.starts_with("http://"));
1304+
1305+
let test = |integration| async move {
1306+
// Localstack doesn't support listing with spaces https://github.com/localstack/localstack/issues/6328
1307+
put_get_delete_list_opts(&integration, is_local).await;
13071308
list_uses_directories_correctly(&integration).await;
13081309
list_with_delimiter(&integration).await;
13091310
rename_and_copy(&integration).await;
13101311
stream_get(&integration).await;
1311-
});
1312-
shutdown();
1313-
}
1312+
};
13141313

1315-
#[tokio::test]
1316-
async fn s3_test() {
1317-
let config = maybe_skip_integration!();
1318-
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
1319-
let integration = config.build().unwrap();
1314+
let (handle, shutdown) = dedicated_tokio();
13201315

1321-
// Localstack doesn't support listing with spaces https://github.com/localstack/localstack/issues/6328
1322-
put_get_delete_list_opts(&integration, is_local).await;
1323-
list_uses_directories_correctly(&integration).await;
1324-
list_with_delimiter(&integration).await;
1325-
rename_and_copy(&integration).await;
1326-
stream_get(&integration).await;
1316+
let integration = builder.clone().build().unwrap();
1317+
handle.block_on(test(integration));
13271318

13281319
// run integration test with unsigned payload enabled
1329-
let config = maybe_skip_integration!().with_unsigned_payload(true);
1330-
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
1331-
let integration = config.build().unwrap();
1332-
put_get_delete_list_opts(&integration, is_local).await;
1320+
let integration = builder.clone().with_unsigned_payload(true).build().unwrap();
1321+
handle.block_on(test(integration));
13331322

13341323
// run integration test with checksum set to sha256
1335-
let config = maybe_skip_integration!().with_checksum_algorithm(Checksum::SHA256);
1336-
let is_local = matches!(&config.endpoint, Some(e) if e.starts_with("http://"));
1337-
let integration = config.build().unwrap();
1338-
put_get_delete_list_opts(&integration, is_local).await;
1324+
let integration = builder
1325+
.clone()
1326+
.with_checksum_algorithm(Checksum::SHA256)
1327+
.build()
1328+
.unwrap();
1329+
handle.block_on(test(integration));
1330+
1331+
// run integration test without tokio runtime
1332+
let integration = builder.with_tokio_runtime(handle).build().unwrap();
1333+
futures::executor::block_on(test(integration));
1334+
1335+
shutdown();
13391336
}
13401337

13411338
#[tokio::test]

object_store/src/azure/client.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ use crate::client::pagination::stream_paginated;
2121
use crate::client::retry::{ClientConfig, RetryExt};
2222
use crate::path::DELIMITER;
2323
use crate::util::{deserialize_rfc1123, format_http_range, format_prefix};
24-
use crate::{
25-
BoxStream, ClientOptions, ListResult, ObjectMeta, Path, Result,
26-
StreamExt,
27-
};
24+
use crate::{BoxStream, ClientOptions, ListResult, ObjectMeta, Path, Result, StreamExt};
2825
use base64::prelude::BASE64_STANDARD;
2926
use base64::Engine;
3027
use bytes::{Buf, Bytes};

object_store/src/azure/mod.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -1137,30 +1137,27 @@ mod tests {
11371137
}};
11381138
}
11391139

1140-
#[test]
1141-
fn azure_blob_non_tokio() {
1142-
let (handle, shutdown) = dedicated_tokio();
1143-
let config = maybe_skip_integration!();
1144-
let integration = config.with_tokio_runtime(handle).build().unwrap();
1145-
futures::executor::block_on(async move {
1140+
#[tokio::test]
1141+
async fn azure_blob_test() {
1142+
let builder = maybe_skip_integration!();
1143+
let test = |integration| async move {
11461144
put_get_delete_list_opts(&integration, false).await;
11471145
list_uses_directories_correctly(&integration).await;
11481146
list_with_delimiter(&integration).await;
11491147
rename_and_copy(&integration).await;
1148+
copy_if_not_exists(&integration).await;
11501149
stream_get(&integration).await;
1151-
});
1152-
shutdown();
1153-
}
1150+
};
11541151

1155-
#[tokio::test]
1156-
async fn azure_blob_test() {
1157-
let integration = maybe_skip_integration!().build().unwrap();
1158-
put_get_delete_list_opts(&integration, false).await;
1159-
list_uses_directories_correctly(&integration).await;
1160-
list_with_delimiter(&integration).await;
1161-
rename_and_copy(&integration).await;
1162-
copy_if_not_exists(&integration).await;
1163-
stream_get(&integration).await;
1152+
let (handle, shutdown) = dedicated_tokio();
1153+
1154+
let integration = builder.clone().build().unwrap();
1155+
handle.block_on(test(integration));
1156+
1157+
let integration = builder.with_tokio_runtime(handle).build().unwrap();
1158+
futures::executor::block_on(test(integration));
1159+
1160+
shutdown();
11641161
}
11651162

11661163
// test for running integration test against actual blob service with service principal

object_store/src/gcp/mod.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -1262,35 +1262,32 @@ mod test {
12621262
}
12631263

12641264
#[test]
1265-
fn gcs_non_tokio() {
1266-
let (handle, shutdown) = dedicated_tokio();
1267-
let config = maybe_skip_integration!();
1268-
let integration = config.with_tokio_runtime(handle).build().unwrap();
1269-
futures::executor::block_on(async move {
1265+
fn gcs_test() {
1266+
let builder = maybe_skip_integration!();
1267+
let test = |integration: GoogleCloudStorage| async move {
12701268
put_get_delete_list(&integration).await;
12711269
list_uses_directories_correctly(&integration).await;
12721270
list_with_delimiter(&integration).await;
12731271
rename_and_copy(&integration).await;
1274-
});
1275-
shutdown();
1276-
}
1272+
if integration.client.base_url == default_gcs_base_url() {
1273+
// Fake GCS server doesn't currently honor ifGenerationMatch
1274+
// https://github.com/fsouza/fake-gcs-server/issues/994
1275+
copy_if_not_exists(&integration).await;
1276+
// Fake GCS server does not yet implement XML Multipart uploads
1277+
// https://github.com/fsouza/fake-gcs-server/issues/852
1278+
stream_get(&integration).await;
1279+
}
1280+
};
12771281

1278-
#[tokio::test]
1279-
async fn gcs_test() {
1280-
let integration = maybe_skip_integration!().build().unwrap();
1282+
let (handle, shutdown) = dedicated_tokio();
12811283

1282-
put_get_delete_list(&integration).await;
1283-
list_uses_directories_correctly(&integration).await;
1284-
list_with_delimiter(&integration).await;
1285-
rename_and_copy(&integration).await;
1286-
if integration.client.base_url == default_gcs_base_url() {
1287-
// Fake GCS server doesn't currently honor ifGenerationMatch
1288-
// https://github.com/fsouza/fake-gcs-server/issues/994
1289-
copy_if_not_exists(&integration).await;
1290-
// Fake GCS server does not yet implement XML Multipart uploads
1291-
// https://github.com/fsouza/fake-gcs-server/issues/852
1292-
stream_get(&integration).await;
1293-
}
1284+
let integration = builder.clone().build().unwrap();
1285+
handle.block_on(test(integration));
1286+
1287+
let integration = builder.with_tokio_runtime(handle).build().unwrap();
1288+
futures::executor::block_on(test(integration));
1289+
1290+
shutdown();
12941291
}
12951292

12961293
#[tokio::test]

object_store/src/http/mod.rs

+13-32
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ mod tests {
283283

284284
use super::*;
285285

286-
#[tokio::test]
287-
async fn http_test() {
286+
#[test]
287+
fn http_test() {
288288
dotenv::dotenv().ok();
289289
let force = std::env::var("TEST_INTEGRATION");
290290
if force.is_err() {
@@ -293,45 +293,26 @@ mod tests {
293293
}
294294
let url = std::env::var("HTTP_URL").expect("HTTP_URL must be set");
295295
let options = ClientOptions::new().with_allow_http(true);
296-
let integration = HttpBuilder::new()
296+
let builder = HttpBuilder::new()
297297
.with_url(url)
298-
.with_client_options(options)
299-
.build()
300-
.unwrap();
301-
302-
put_get_delete_list_opts(&integration, false).await;
303-
list_uses_directories_correctly(&integration).await;
304-
list_with_delimiter(&integration).await;
305-
rename_and_copy(&integration).await;
306-
copy_if_not_exists(&integration).await;
307-
}
298+
.with_client_options(options);
308299

309-
#[test]
310-
fn http_non_tokio() {
311300
let (handle, shutdown) = dedicated_tokio();
312301

313-
dotenv::dotenv().ok();
314-
let force = std::env::var("TEST_INTEGRATION");
315-
if force.is_err() {
316-
eprintln!("skipping HTTP integration test - set TEST_INTEGRATION to run");
317-
return;
318-
}
319-
let url = std::env::var("HTTP_URL").expect("HTTP_URL must be set");
320-
let options = ClientOptions::new().with_allow_http(true);
321-
let integration = HttpBuilder::new()
322-
.with_url(url)
323-
.with_client_options(options)
324-
.with_tokio_runtime(handle)
325-
.build()
326-
.unwrap();
327-
328-
futures::executor::block_on(async move {
302+
let test = |integration| async move {
329303
put_get_delete_list_opts(&integration, false).await;
330304
list_uses_directories_correctly(&integration).await;
331305
list_with_delimiter(&integration).await;
332306
rename_and_copy(&integration).await;
333307
copy_if_not_exists(&integration).await;
334-
});
308+
};
309+
310+
let integration = builder.clone().build().unwrap();
311+
handle.block_on(test(integration));
312+
313+
let integration = builder.with_tokio_runtime(handle).build().unwrap();
314+
futures::executor::block_on(test(integration));
315+
335316
shutdown();
336317
}
337318
}

0 commit comments

Comments
 (0)