Skip to content

Commit c7e4d51

Browse files
authored
[Storage] Improve live test probe. (Azure#20639)
* try that. * why so many probes ?
1 parent 438ad43 commit c7e4d51

File tree

2 files changed

+104
-67
lines changed

2 files changed

+104
-67
lines changed

sdk/storage/Azure.Storage.Blobs/tests/BlobTestEnvironment.cs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics;
56
using System.Threading.Tasks;
67
using Azure.Storage.Blobs.Specialized;
8+
using Azure.Storage.Sas;
79
using Azure.Storage.Test;
810
using Azure.Storage.Test.Shared;
911
using NUnit.Framework;
@@ -19,35 +21,47 @@ protected override async ValueTask<bool> IsEnvironmentReadyAsync()
1921

2022
private async Task<bool> DoesOAuthWorkAsync()
2123
{
22-
TestContext.Error.WriteLine("Blob Probing OAuth");
24+
TestContext.Error.WriteLine($"Blob Probing OAuth {Process.GetCurrentProcess().Id}");
2325

2426
try
2527
{
26-
BlobServiceClient serviceClient = new BlobServiceClient(
27-
new Uri(TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint),
28-
GetOAuthCredential(TestConfigurations.DefaultTargetOAuthTenant));
29-
await serviceClient.GetPropertiesAsync();
30-
var containerName = Guid.NewGuid().ToString();
31-
var containerClient = serviceClient.GetBlobContainerClient(containerName);
32-
await containerClient.CreateIfNotExistsAsync();
33-
try
28+
for (int i = 0; i < 10; i++)
3429
{
35-
await containerClient.GetPropertiesAsync();
36-
var blobName = Guid.NewGuid().ToString();
37-
var blobClient = containerClient.GetAppendBlobClient(blobName);
38-
await blobClient.CreateIfNotExistsAsync();
39-
await blobClient.GetPropertiesAsync();
40-
}
41-
finally
42-
{
43-
await containerClient.DeleteIfExistsAsync();
30+
BlobServiceClient serviceClient = new BlobServiceClient(
31+
new Uri(TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint),
32+
GetOAuthCredential(TestConfigurations.DefaultTargetOAuthTenant));
33+
await serviceClient.GetPropertiesAsync();
34+
var containerName = Guid.NewGuid().ToString();
35+
var containerClient = serviceClient.GetBlobContainerClient(containerName);
36+
await containerClient.CreateIfNotExistsAsync();
37+
try
38+
{
39+
await containerClient.GetPropertiesAsync();
40+
var blobName = Guid.NewGuid().ToString();
41+
var blobClient = containerClient.GetAppendBlobClient(blobName);
42+
await blobClient.CreateIfNotExistsAsync();
43+
await blobClient.GetPropertiesAsync();
44+
45+
var userDelegationKey = await serviceClient.GetUserDelegationKeyAsync(startsOn: null, expiresOn: DateTimeOffset.UtcNow.AddHours(1));
46+
var sasBuilder = new BlobSasBuilder(BlobSasPermissions.All, DateTimeOffset.UtcNow.AddHours(1))
47+
{
48+
BlobContainerName = containerName,
49+
BlobName = blobName,
50+
};
51+
var sas = sasBuilder.ToSasQueryParameters(userDelegationKey.Value, serviceClient.AccountName).ToString();
52+
await new BlobBaseClient(blobClient.Uri, new AzureSasCredential(sas)).GetPropertiesAsync();
53+
}
54+
finally
55+
{
56+
await containerClient.DeleteIfExistsAsync();
57+
}
4458
}
4559
} catch (RequestFailedException e) when (e.Status == 403 && e.ErrorCode == "AuthorizationPermissionMismatch")
4660
{
47-
TestContext.Error.WriteLine("Blob Probing OAuth - not ready");
61+
TestContext.Error.WriteLine($"Blob Probing OAuth - not ready {Process.GetCurrentProcess().Id}");
4862
return false;
4963
}
50-
TestContext.Error.WriteLine("Blob Probing OAuth - ready");
64+
TestContext.Error.WriteLine($"Blob Probing OAuth - ready {Process.GetCurrentProcess().Id}");
5165
return true;
5266
}
5367
}

sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestEnvironment.cs

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Threading.Tasks;
78
using Azure.Storage.Blobs;
89
using Azure.Storage.Blobs.Specialized;
10+
using Azure.Storage.Sas;
911
using Azure.Storage.Test;
1012
using Azure.Storage.Test.Shared;
1113
using NUnit.Framework;
@@ -21,68 +23,89 @@ protected override async ValueTask<bool> IsEnvironmentReadyAsync()
2123

2224
private async Task<bool> DoesOAuthWorkAsync()
2325
{
24-
TestContext.Error.WriteLine("Datalake Probing OAuth");
26+
TestContext.Error.WriteLine($"Datalake Probing OAuth {Process.GetCurrentProcess().Id}");
2527

2628
try
2729
{
28-
// Check flat account. For some reason we observe failures if that one doesn't work before we start datalake run.
30+
for (int i = 0; i < 10; i++)
2931
{
30-
BlobServiceClient serviceClient = new BlobServiceClient(
31-
new Uri(TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint),
32-
GetOAuthCredential(TestConfigurations.DefaultTargetOAuthTenant));
33-
await serviceClient.GetPropertiesAsync();
34-
var containerName = Guid.NewGuid().ToString();
35-
var containerClient = serviceClient.GetBlobContainerClient(containerName);
36-
await containerClient.CreateIfNotExistsAsync();
37-
try
32+
// Check flat account. For some reason we observe failures if that one doesn't work before we start datalake run.
3833
{
39-
await containerClient.GetPropertiesAsync();
40-
var blobName = Guid.NewGuid().ToString();
41-
var blobClient = containerClient.GetAppendBlobClient(blobName);
42-
await blobClient.CreateIfNotExistsAsync();
43-
await blobClient.GetPropertiesAsync();
44-
}
45-
finally
46-
{
47-
await containerClient.DeleteIfExistsAsync();
48-
}
49-
}
34+
BlobServiceClient serviceClient = new BlobServiceClient(
35+
new Uri(TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint),
36+
GetOAuthCredential(TestConfigurations.DefaultTargetOAuthTenant));
37+
await serviceClient.GetPropertiesAsync();
38+
var containerName = Guid.NewGuid().ToString();
39+
var containerClient = serviceClient.GetBlobContainerClient(containerName);
40+
await containerClient.CreateIfNotExistsAsync();
41+
try
42+
{
43+
await containerClient.GetPropertiesAsync();
44+
var blobName = Guid.NewGuid().ToString();
45+
var blobClient = containerClient.GetAppendBlobClient(blobName);
46+
await blobClient.CreateIfNotExistsAsync();
47+
await blobClient.GetPropertiesAsync();
5048

51-
// Check hierarchical account.
52-
{
53-
DataLakeServiceClient serviceClient = new DataLakeServiceClient(
54-
new Uri(TestConfigurations.DefaultTargetHierarchicalNamespaceTenant.BlobServiceEndpoint),
55-
GetOAuthCredential(TestConfigurations.DefaultTargetHierarchicalNamespaceTenant));
56-
await serviceClient.GetPropertiesAsync();
57-
var fileSystemName = Guid.NewGuid().ToString();
58-
var fileSystemClient = serviceClient.GetFileSystemClient(fileSystemName);
59-
await fileSystemClient.CreateIfNotExistsAsync();
60-
try
61-
{
62-
var directoryName = Guid.NewGuid().ToString();
63-
var directoryClient = fileSystemClient.GetDirectoryClient(directoryName);
64-
await directoryClient.CreateIfNotExistsAsync();
65-
await directoryClient.GetPropertiesAsync();
66-
var fileName = Guid.NewGuid().ToString();
67-
var fileClient = directoryClient.GetFileClient(fileName);
68-
await fileClient.CreateIfNotExistsAsync();
69-
await fileClient.GetPropertiesAsync();
70-
// call some APIs that talk to DFS endoint as well.
71-
await fileClient.AppendAsync(new MemoryStream(new byte[] { 1 }), 0);
72-
await fileClient.GetAccessControlAsync();
49+
var userDelegationKey = await serviceClient.GetUserDelegationKeyAsync(startsOn: null, expiresOn: DateTimeOffset.UtcNow.AddHours(1));
50+
var sasBuilder = new BlobSasBuilder(BlobSasPermissions.All, DateTimeOffset.UtcNow.AddHours(1))
51+
{
52+
BlobContainerName = containerName,
53+
BlobName = blobName,
54+
};
55+
var sas = sasBuilder.ToSasQueryParameters(userDelegationKey.Value, serviceClient.AccountName).ToString();
56+
await new BlobBaseClient(blobClient.Uri, new AzureSasCredential(sas)).GetPropertiesAsync();
57+
}
58+
finally
59+
{
60+
await containerClient.DeleteIfExistsAsync();
61+
}
7362
}
74-
finally
63+
64+
// Check hierarchical account.
7565
{
76-
await fileSystemClient.DeleteIfExistsAsync();
66+
DataLakeServiceClient serviceClient = new DataLakeServiceClient(
67+
new Uri(TestConfigurations.DefaultTargetHierarchicalNamespaceTenant.BlobServiceEndpoint),
68+
GetOAuthCredential(TestConfigurations.DefaultTargetHierarchicalNamespaceTenant));
69+
await serviceClient.GetPropertiesAsync();
70+
var fileSystemName = Guid.NewGuid().ToString();
71+
var fileSystemClient = serviceClient.GetFileSystemClient(fileSystemName);
72+
await fileSystemClient.CreateIfNotExistsAsync();
73+
try
74+
{
75+
var directoryName = Guid.NewGuid().ToString();
76+
var directoryClient = fileSystemClient.GetDirectoryClient(directoryName);
77+
await directoryClient.CreateIfNotExistsAsync();
78+
await directoryClient.GetPropertiesAsync();
79+
var fileName = Guid.NewGuid().ToString();
80+
var fileClient = directoryClient.GetFileClient(fileName);
81+
await fileClient.CreateIfNotExistsAsync();
82+
await fileClient.GetPropertiesAsync();
83+
// call some APIs that talk to DFS endoint as well.
84+
await fileClient.AppendAsync(new MemoryStream(new byte[] { 1 }), 0);
85+
await fileClient.GetAccessControlAsync();
86+
87+
var userDelegationKey = await serviceClient.GetUserDelegationKeyAsync(startsOn: null, expiresOn: DateTimeOffset.UtcNow.AddHours(1));
88+
var sasBuilder = new DataLakeSasBuilder(DataLakeSasPermissions.All, DateTimeOffset.UtcNow.AddHours(1))
89+
{
90+
FileSystemName = fileSystemName,
91+
Path = fileClient.Path,
92+
};
93+
var sas = sasBuilder.ToSasQueryParameters(userDelegationKey.Value, serviceClient.AccountName).ToString();
94+
await new DataLakeFileClient(fileClient.Uri, new AzureSasCredential(sas)).GetPropertiesAsync();
95+
}
96+
finally
97+
{
98+
await fileSystemClient.DeleteIfExistsAsync();
99+
}
77100
}
78101
}
79102
}
80103
catch (RequestFailedException e) when (e.Status == 403 && e.ErrorCode == "AuthorizationPermissionMismatch")
81104
{
82-
TestContext.Error.WriteLine("Datalake Probing OAuth - not ready");
105+
TestContext.Error.WriteLine($"Datalake Probing OAuth - not ready {Process.GetCurrentProcess().Id}");
83106
return false;
84107
}
85-
TestContext.Error.WriteLine("Datalake Probing OAuth - ready");
108+
TestContext.Error.WriteLine($"Datalake Probing OAuth - ready {Process.GetCurrentProcess().Id}");
86109
return true;
87110
}
88111
}

0 commit comments

Comments
 (0)