Skip to content

Commit 4fdd7ba

Browse files
committed
Use internal Retry consistently
Also fixes up one paragraph in Secrets' README.md to be consistent with the others'.
1 parent cb8d3b6 commit 4fdd7ba

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

sdk/keyvault/azure_security_keyvault_certificates/tests/readme.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use azure_core::{
5-
error::{ErrorKind, Result},
6-
http::StatusCode,
7-
time::Duration,
8-
};
4+
use azure_core::{error::Result, http::StatusCode};
95
use azure_core_test::{recorded, TestContext, TestMode};
106
use azure_security_keyvault_certificates::{CertificateClient, CertificateClientOptions};
117
use azure_security_keyvault_keys::{KeyClient, KeyClientOptions};
8+
use azure_security_keyvault_test::Retry;
129
use include_file::include_markdown;
1310

1411
#[recorded::test]
@@ -55,17 +52,22 @@ async fn readme(ctx: TestContext) -> Result<()> {
5552
println!("Delete a certificate");
5653
include_markdown!("README.md", "delete_certificate", scope);
5754

58-
// Make sure the certificate gets purged (may not take immediate effect).
5955
println!("Purge a certificate");
60-
for _ in 0..5 {
56+
// Because deletes may not happen right away, try purging in a loop.
57+
let mut retry = match recording.test_mode() {
58+
TestMode::Playback => Retry::immediate(),
59+
_ => Retry::progressive(None),
60+
};
61+
62+
loop {
6163
match client
6264
.purge_deleted_certificate("certificate-name", None)
6365
.await
6466
{
6567
Ok(_) => break,
66-
Err(err) if matches!(err.kind(), ErrorKind::HttpResponse { status, .. } if *status == StatusCode::Conflict) => {
67-
if recording.test_mode() != TestMode::Playback {
68-
azure_core::sleep(Duration::seconds(1)).await;
68+
Err(err) if matches!(err.http_status(), Some(StatusCode::Conflict)) => {
69+
if retry.next().await.is_none() {
70+
return Err(err);
6971
}
7072
}
7173
Err(err) => return Err(err),

sdk/keyvault/azure_security_keyvault_keys/tests/readme.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use azure_core::{
5-
error::{ErrorKind, Result},
6-
http::StatusCode,
7-
time::Duration,
8-
};
4+
use azure_core::{error::Result, http::StatusCode};
95
use azure_core_test::{recorded, TestContext, TestMode};
106
use azure_security_keyvault_keys::{KeyClient, KeyClientOptions};
117
use include_file::include_markdown;
128

139
#[recorded::test]
1410
async fn readme(ctx: TestContext) -> Result<()> {
11+
use azure_security_keyvault_test::Retry;
12+
1513
let recording = ctx.recording();
1614

1715
let mut options = KeyClientOptions::default();
@@ -46,14 +44,19 @@ async fn readme(ctx: TestContext) -> Result<()> {
4644
println!("Delete a key");
4745
include_markdown!("README.md", "delete_key", scope);
4846

49-
// Make sure the key gets purged (may not take immediate effect).
5047
println!("Purge a key");
51-
for _ in 0..5 {
48+
// Because deletes may not happen right away, try purging in a loop.
49+
let mut retry = match recording.test_mode() {
50+
TestMode::Playback => Retry::immediate(),
51+
_ => Retry::progressive(None),
52+
};
53+
54+
loop {
5255
match client.purge_deleted_key("key-name", None).await {
5356
Ok(_) => break,
54-
Err(err) if matches!(err.kind(), ErrorKind::HttpResponse { status, .. } if *status == StatusCode::Conflict) => {
55-
if recording.test_mode() != TestMode::Playback {
56-
azure_core::sleep(Duration::seconds(1)).await;
57+
Err(err) if matches!(err.http_status(), Some(StatusCode::Conflict)) => {
58+
if retry.next().await.is_none() {
59+
return Err(err);
5760
}
5861
}
5962
Err(err) => return Err(err),

sdk/keyvault/azure_security_keyvault_secrets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cargo add azure_identity tokio
4040

4141
In order to interact with the Azure Key Vault service, you'll need to create an instance of the `SecretClient`. You need a **vault url**, which you may see as "DNS Name" in the portal, and credentials to instantiate a client object.
4242

43-
The example shown below use a `DeveloperToolsCredential`, which is appropriate for most local development environments. Additionally, we recommend using a managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity] documentation.
43+
The example shown below uses a `DeveloperToolsCredential`, which is appropriate for local development environments. We recommend using a managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity] documentation.
4444

4545
The `DeveloperToolsCredential` will automatically pick up on an Azure CLI authentication. Ensure you are logged in with the Azure CLI:
4646

sdk/keyvault/azure_security_keyvault_secrets/tests/readme.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use azure_core::{
5-
error::{ErrorKind, Result},
6-
http::StatusCode,
7-
time::Duration,
8-
};
4+
use azure_core::{error::Result, http::StatusCode};
95
use azure_core_test::{recorded, TestContext, TestMode};
106
use azure_security_keyvault_secrets::{SecretClient, SecretClientOptions};
117
use include_file::include_markdown;
128

139
#[recorded::test]
1410
async fn readme(ctx: TestContext) -> Result<()> {
11+
use azure_security_keyvault_test::Retry;
12+
1513
let recording = ctx.recording();
1614

1715
let mut options = SecretClientOptions::default();
@@ -42,14 +40,19 @@ async fn readme(ctx: TestContext) -> Result<()> {
4240
println!("Delete a secret");
4341
include_markdown!("README.md", "delete_secret", scope);
4442

45-
// Make sure the secret gets purged (may not take immediate effect).
4643
println!("Purge a secret");
47-
for _ in 0..5 {
44+
// Because deletes may not happen right away, try purging in a loop.
45+
let mut retry = match recording.test_mode() {
46+
TestMode::Playback => Retry::immediate(),
47+
_ => Retry::progressive(None),
48+
};
49+
50+
loop {
4851
match client.purge_deleted_secret("secret-name", None).await {
4952
Ok(_) => break,
50-
Err(err) if matches!(err.kind(), ErrorKind::HttpResponse { status, .. } if *status == StatusCode::Conflict) => {
51-
if recording.test_mode() != TestMode::Playback {
52-
azure_core::sleep(Duration::seconds(1)).await;
53+
Err(err) if matches!(err.http_status(), Some(StatusCode::Conflict)) => {
54+
if retry.next().await.is_none() {
55+
return Err(err);
5356
}
5457
}
5558
Err(err) => return Err(err),

0 commit comments

Comments
 (0)