in src/aws/mod.rs [828:876]
fn s3_alternate_threadpool_spawned_request_connector() {
maybe_skip_integration!();
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel::<()>();
// Runtime with I/O enabled
let io_runtime = tokio::runtime::Builder::new_current_thread()
.enable_all() // <-- turns on IO
.build()
.unwrap();
// Runtime without I/O enabled
let non_io_runtime = tokio::runtime::Builder::new_current_thread()
// note: no call to enable_all
.build()
.unwrap();
// run the io runtime in a different thread
let io_handle = io_runtime.handle().clone();
let thread_handle = std::thread::spawn(move || {
io_runtime.block_on(async move {
shutdown_rx.await.unwrap();
});
});
let store = AmazonS3Builder::from_env()
// use different bucket to avoid collisions with other tests
.with_bucket_name("test-bucket-for-spawn")
.with_http_connector(SpawnedReqwestConnector::new(io_handle))
.build()
.unwrap();
// run a request on the non io runtime -- will fail if the connector
// does not spawn the request to the io runtime
non_io_runtime
.block_on(async move {
let path = Path::from("alternate_threadpool/test.txt");
store.delete(&path).await.ok(); // remove the file if it exists from prior runs
store.put(&path, "foo".into()).await?;
let res = store.get(&path).await?.bytes().await?;
assert_eq!(res.as_ref(), b"foo");
store.delete(&path).await?; // cleanup
Ok(()) as Result<()>
})
.expect("failed to run request on non io runtime");
// shutdown the io runtime and thread
shutdown_tx.send(()).ok();
thread_handle.join().expect("runtime thread panicked");
}