Skip to content

Commit ee6373a

Browse files
Yield in blob container client; read environment variables from env file (Azure#3245)
1 parent 9894c4d commit ee6373a

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

sdk/core/azure_core/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ impl AsyncRuntime for CustomRuntime {
546546
fn sleep(&self, duration: Duration) -> TaskFuture {
547547
unimplemented!("Custom sleep not implemented");
548548
}
549+
fn yield_now(&self) -> TaskFuture {
550+
unimplemented!("Custom yield not implemented");
551+
}
549552
}
550553

551554
set_async_runtime(Arc::new(CustomRuntime)).expect("Failed to set async runtime");

sdk/core/typespec_client_core/src/async_runtime/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ pub trait AsyncRuntime: Send + Sync {
115115
/// # Returns
116116
/// A future that resolves after the specified duration has elapsed.
117117
fn sleep(&self, duration: Duration) -> TaskFuture;
118+
119+
/// Yield the current task back to the runtime scheduler.
120+
fn yield_now(&self) -> TaskFuture;
118121
}
119122

120123
static ASYNC_RUNTIME_IMPLEMENTATION: OnceLock<Arc<dyn AsyncRuntime>> = OnceLock::new();
@@ -176,6 +179,9 @@ pub fn get_async_runtime() -> Arc<dyn AsyncRuntime> {
176179
/// fn sleep(&self, duration: typespec_client_core::time::Duration) -> TaskFuture {
177180
/// unimplemented!("Custom sleep not implemented");
178181
/// }
182+
/// fn yield_now(&self) -> TaskFuture {
183+
/// unimplemented!("Custom yield not implemented");
184+
/// }
179185
/// }
180186
///
181187
/// set_async_runtime(Arc::new(CustomRuntime)).expect("Failed to set async runtime");

sdk/core/typespec_client_core/src/async_runtime/standard_runtime.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ impl AsyncRuntime for StdRuntime {
161161
duration,
162162
})
163163
}
164+
165+
fn yield_now(&self) -> TaskFuture {
166+
#[cfg(target_arch = "wasm32")]
167+
{
168+
panic!("yield_now is not supported on wasm32")
169+
}
170+
#[cfg(not(target_arch = "wasm32"))]
171+
{
172+
std::thread::yield_now();
173+
Box::pin(future::ready(()))
174+
}
175+
}
164176
}
165177

166178
#[cfg(not(target_arch = "wasm32"))]

sdk/core/typespec_client_core/src/async_runtime/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ impl AsyncRuntime for TestRuntime {
260260
fn sleep(&self, _duration: Duration) -> TaskFuture {
261261
unimplemented!("TestRuntime does not support sleeping");
262262
}
263+
264+
fn yield_now(&self) -> TaskFuture {
265+
unimplemented!("TestRuntime does not support yielding");
266+
}
263267
}
264268

265269
// This test is ignored because by default, cargo test runs all tests in parallel, but

sdk/core/typespec_client_core/src/async_runtime/tokio_runtime.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ impl AsyncRuntime for TokioRuntime {
2525
.expect("Failed to convert duration to tokio format"),
2626
))
2727
}
28+
29+
fn yield_now(&self) -> TaskFuture {
30+
Box::pin(async {
31+
tokio::task::yield_now().await;
32+
})
33+
}
2834
}

sdk/storage/azure_storage_blob/perf/list_blob_test.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use futures::{FutureExt, TryStreamExt};
1313

1414
pub struct ListBlobTest {
1515
count: u32,
16-
endpoint: String,
16+
endpoint: Option<String>,
1717
client: OnceLock<BlobContainerClient>,
1818
}
1919

@@ -27,19 +27,10 @@ impl ListBlobTest {
2727
println!("Parsed count: {}", count);
2828

2929
let endpoint: Option<&String> = runner.try_get_test_arg("endpoint")?;
30-
let endpoint = match endpoint {
31-
Some(e) => e.clone(),
32-
None => format!(
33-
"https://{}.blob.core.windows.net",
34-
std::env::var("AZURE_STORAGE_ACCOUNT_NAME")
35-
.expect("AZURE_STORAGE_ACCOUNT_NAME is not set")
36-
),
37-
};
38-
println!("Using endpoint: {}", endpoint);
3930

4031
Ok(Box::new(ListBlobTest {
4132
count,
42-
endpoint,
33+
endpoint: endpoint.cloned(),
4334
client: OnceLock::new(),
4435
}) as Box<dyn PerfTest>)
4536
}
@@ -83,7 +74,15 @@ impl PerfTest for ListBlobTest {
8374
let recording = context.recording();
8475
let credential = recording.credential();
8576
let container_name = format!("perf-container-{}", uuid::Uuid::new_v4());
86-
let client = BlobContainerClient::new(&self.endpoint, container_name, credential, None)?;
77+
let endpoint = match &self.endpoint {
78+
Some(e) => e.clone(),
79+
None => format!(
80+
"https://{}.blob.core.windows.net",
81+
recording.var("AZURE_STORAGE_ACCOUNT_NAME", None)
82+
),
83+
};
84+
println!("Using endpoint: {}", endpoint);
85+
let client = BlobContainerClient::new(&endpoint, container_name, credential, None)?;
8786
self.client.set(client).map_err(|_| {
8887
azure_core::Error::with_message(ErrorKind::Other, "Failed to set client")
8988
})?;

sdk/storage/azure_storage_blob/src/generated/clients/blob_container_client.rs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)