From 5e07e39a8c28910939e9a8cbfee39bfe8f100491 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 26 Feb 2020 16:55:16 -0800 Subject: [PATCH 01/11] Use ShareClient.CreateIfNotExists() to improve test reliability - In test code, all calls to ShareClient.Create() were replaced by ShareClient.CreateIfNotExists(), with the exception of calls explicitly testing Create(). - Even if the share does not exist, ShareClient.Create() can throw ShareAlreadyExists if the server failed to respond to the first HTTP request and it was retried --- .../Azure.Storage.Files.Shares/tests/FileTestBase.cs | 2 +- .../tests/ShareClientTests.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs index c54aafae2815..ba1a749963c8 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs @@ -261,7 +261,7 @@ public class DisposingShare : IAsyncDisposable public static async Task CreateAsync(ShareClient share, IDictionary metadata) { - await share.CreateAsync(metadata: metadata); + await share.CreateIfNotExistsAsync(metadata: metadata); return new DisposingShare(share); } diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs index 8e916ebee2f1..85f33db06f10 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs @@ -85,7 +85,7 @@ ShareClient GetShareClient(string connectionString) => async Task GetFileClient(ShareClient share) { - await share.CreateAsync(); + await share.CreateIfNotExistsAsync(); string dirName = GetNewDirectoryName(); await share.CreateDirectoryAsync(dirName); return InstrumentClient(share.GetDirectoryClient(dirName).GetFileClient(GetNewFileName())); @@ -194,7 +194,7 @@ public async Task CreateAsync_Error() ShareClient share = InstrumentClient(service.GetShareClient(shareName)); // Share is intentionally created twice - await share.CreateAsync(); + await share.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -325,7 +325,7 @@ public async Task CreateIfNotExistsAsync_Exists() var shareName = GetNewShareName(); ShareServiceClient service = GetServiceClient_SharedKey(); ShareClient share = InstrumentClient(service.GetShareClient(shareName)); - await share.CreateAsync(); + await share.CreateIfNotExistsAsync(); // Act Response response = await share.CreateIfNotExistsAsync(); @@ -374,7 +374,7 @@ public async Task ExistsAsync_Exists() var shareName = GetNewShareName(); ShareServiceClient service = GetServiceClient_SharedKey(); ShareClient share = InstrumentClient(service.GetShareClient(shareName)); - await share.CreateAsync(); + await share.CreateIfNotExistsAsync(); // Act Response response = await share.ExistsAsync(); @@ -408,7 +408,7 @@ public async Task DeleteIfExistsAsync_Exists() var shareName = GetNewShareName(); ShareServiceClient service = GetServiceClient_SharedKey(); ShareClient share = InstrumentClient(service.GetShareClient(shareName)); - await share.CreateAsync(); + await share.CreateIfNotExistsAsync(); // Act Response response = await share.DeleteIfExistsAsync(); @@ -710,7 +710,7 @@ public async Task DeleteAsync() var shareName = GetNewShareName(); ShareServiceClient service = GetServiceClient_SharedKey(); ShareClient share = InstrumentClient(service.GetShareClient(shareName)); - await share.CreateAsync(quotaInGB: 1); + await share.CreateIfNotExistsAsync(quotaInGB: 1); // Act Response response = await share.DeleteAsync(false); From d4adf5fac8b4c29abbc3d227338457707cdaa7d9 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 26 Feb 2020 17:10:37 -0800 Subject: [PATCH 02/11] Use ShareDirectoryClient.CreateIfNotExists() to improve test reliability - In test code, all calls to ShareDirectoryClient.Create() were replaced by ShareDirectoryClient.CreateIfNotExists(), with the exception of calls explicitly testing Create(). - Even if the directory does not exist, ShareDirectoryClient.Create() can throw ResourceAlreadyExists if the server failed to respond to the first HTTP request and it was retried --- .../tests/DirectoryClientTests.cs | 24 +++++++++---------- .../tests/FileClientTests.cs | 16 ++++++------- .../tests/FileTestBase.cs | 2 +- .../tests/ShareClientTests.cs | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs index 8d4f2c461801..9a66d3356e97 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs @@ -198,7 +198,7 @@ public async Task CreateAsync_Error() // Arrange ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); // Directory is intentionally created twice - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -248,7 +248,7 @@ public async Task CreateIfNotExists_Exists() ShareClient share = test.Share; string name = GetNewDirectoryName(); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(name)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.CreateIfNotExistsAsync(); @@ -297,7 +297,7 @@ public async Task Exists_Exists() ShareClient share = test.Share; string name = GetNewDirectoryName(); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(name)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.ExistsAsync(); @@ -329,7 +329,7 @@ public async Task DeleteIfExists_Exists() ShareClient share = test.Share; string name = GetNewDirectoryName(); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(name)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.DeleteIfExistsAsync(); @@ -362,7 +362,7 @@ public async Task DeleteIfExists_Error() ShareClient share = test.Share; string name = GetNewDirectoryName(); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(name)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); await directory.CreateFileAsync(GetNewFileName(), Constants.KB); // Act @@ -409,7 +409,7 @@ public async Task GetPropertiesAsync() ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); // Act - Response createResponse = await directory.CreateAsync(); + Response createResponse = await directory.CreateIfNotExistsAsync(); Response getPropertiesResponse = await directory.GetPropertiesAsync(); // Assert @@ -442,7 +442,7 @@ public async Task SetPropertiesAsync_FilePermission() // Arrange ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); var filePermission = "O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-2127521184-1604012920-1887927527-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;S-1-5-21-397955417-626881126-188441444-3053964)"; - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.SetHttpHeadersAsync(filePermission: filePermission); @@ -471,7 +471,7 @@ public async Task SetPropertiesAsync_SmbProperties() }; - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.SetHttpHeadersAsync(smbProperties: smbProperties); @@ -492,7 +492,7 @@ public async Task SetPropertiesAsync_FilePermissionTooLong() // Arrange ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); var filePermission = new string('*', 9 * Constants.KB); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -516,7 +516,7 @@ public async Task SetPropertiesAsync_FilePermissionAndFilePermissionKeySet() { FilePermissionKey = "filePermissionKey" }; - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -573,7 +573,7 @@ public async Task ListFilesAndDirectoriesSegmentAsync() ShareClient share = test.Share; ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); foreach (var fileName in fileNames) { @@ -586,7 +586,7 @@ public async Task ListFilesAndDirectoriesSegmentAsync() { ShareDirectoryClient subDir = InstrumentClient(directory.GetSubdirectoryClient(subDirName)); - await subDir.CreateAsync(); + await subDir.CreateIfNotExistsAsync(); } var directories = new List(); diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs index 01dd5c8151c1..7128629c83fc 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs @@ -233,7 +233,7 @@ public async Task CreateAsync_SmbProperties() Response createPermissionResponse = await share.CreatePermissionAsync(permission); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); ShareFileClient file = InstrumentClient(directory.GetFileClient(GetNewFileName())); var smbProperties = new FileSmbProperties @@ -819,7 +819,7 @@ public async Task SetPropertiesAsync_SmbProperties() Response createPermissionResponse = await share.CreatePermissionAsync(permission); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); ShareFileClient file = InstrumentClient(directory.GetFileClient(GetNewFileName())); var smbProperties = new FileSmbProperties @@ -1559,7 +1559,7 @@ public async Task DownloadAsync_WithUnreliableConnection() new StorageSharedKeyCredential(TestConfigDefault.AccountName, TestConfigDefault.AccountKey), GetFaultyFileConnectionOptions(raiseAt: 256 * Constants.KB))); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Arrange var fileName = GetNewFileName(); @@ -1975,7 +1975,7 @@ public async Task UploadRangeAsync_WithUnreliableConnection() TestConfigDefault.AccountKey), GetFaultyFileConnectionOptions())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Arrange var fileName = GetNewFileName(); @@ -2025,7 +2025,7 @@ public async Task UploadRangeFromUriAsync() // Arrange var directoryName = this.GetNewDirectoryName(); var directory = this.InstrumentClient(share.GetDirectoryClient(directoryName)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); var fileName = this.GetNewFileName(); var data = this.GetRandomBuffer(Constants.KB); @@ -2078,7 +2078,7 @@ public async Task UploadRangeFromUriAsync_Lease() // Arrange var directoryName = this.GetNewDirectoryName(); var directory = this.InstrumentClient(share.GetDirectoryClient(directoryName)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); var fileName = this.GetNewFileName(); var data = this.GetRandomBuffer(Constants.KB); @@ -2127,7 +2127,7 @@ public async Task UploadRangeFromUriAsync_InvalidLease() // Arrange var directoryName = this.GetNewDirectoryName(); var directory = this.InstrumentClient(share.GetDirectoryClient(directoryName)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); var fileName = this.GetNewFileName(); var data = this.GetRandomBuffer(Constants.KB); @@ -2175,7 +2175,7 @@ public async Task UploadRangeFromUriAsync_Error() // Arrange var directoryName = this.GetNewDirectoryName(); var directory = this.InstrumentClient(share.GetDirectoryClient(directoryName)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); var fileName = this.GetNewFileName(); var sourceFile = this.InstrumentClient(directory.GetFileClient(fileName)); diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs index ba1a749963c8..592a917e0256 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs @@ -296,7 +296,7 @@ public class DisposingDirectory : IAsyncDisposable public static async Task CreateAsync(DisposingShare test, ShareDirectoryClient directory) { - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); return new DisposingDirectory(test, directory); } diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs index 85f33db06f10..c8d9c5d4079e 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs @@ -753,7 +753,7 @@ public async Task DeleteDirectoryAsync() ShareClient share = test.Share; string directoryName = GetNewDirectoryName(); ShareDirectoryClient directory = InstrumentClient(share.GetDirectoryClient(directoryName)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act await share.DeleteDirectoryAsync(directoryName); From 048f2684e28c4a0aa1cc7397b842d02cac107ecb Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 26 Feb 2020 18:27:46 -0800 Subject: [PATCH 03/11] [BlobContainerClient] Use IfExists APIs to improve test reliability --- .../Azure.Storage.Blobs/tests/BlobTestBase.cs | 4 +- .../tests/ContainerClientTests.cs | 112 +++++++++--------- .../tests/StorageSharedKeyCredentialsTests.cs | 5 +- 3 files changed, 61 insertions(+), 60 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs index d071bc3f8587..957d30b8d30a 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs @@ -240,7 +240,7 @@ public async Task GetTestContainerAsync( } BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(containerName)); - await container.CreateAsync(metadata: metadata, publicAccessType: publicAccessType.Value); + await container.CreateIfNotExistsAsync(metadata: metadata, publicAccessType: publicAccessType.Value); return new DisposingContainer(container); } @@ -538,7 +538,7 @@ public async ValueTask DisposeAsync() { try { - await Container.DeleteAsync(); + await Container.DeleteIfExistsAsync(); Container = null; } catch diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs index 48f22c6d31bb..eefc86fbad9c 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs @@ -80,10 +80,10 @@ public async Task Perform_Ctor_ConnectionString_Sas(bool includeTable) try { // Act - await containerClient1.CreateAsync(); + await containerClient1.CreateIfNotExistsAsync(); BlobClient blob1 = InstrumentClient(containerClient1.GetBlobClient(GetNewBlobName())); - await containerClient2.CreateAsync(); + await containerClient2.CreateIfNotExistsAsync(); BlobClient blob2 = InstrumentClient(containerClient2.GetBlobClient(GetNewBlobName())); var data = GetRandomBuffer(Constants.KB); @@ -104,8 +104,8 @@ public async Task Perform_Ctor_ConnectionString_Sas(bool includeTable) finally { // Clean up - await containerClient1.DeleteAsync(); - await containerClient2.DeleteAsync(); + await containerClient1.DeleteIfExistsAsync(); + await containerClient2.DeleteIfExistsAsync(); } } @@ -126,7 +126,7 @@ public async Task Ctor_ConnectionString_Sas_Resource_Types_Container() { // Act // This should succeed as we have Container resourceType permission - await containerClient.CreateAsync(); + await containerClient.CreateIfNotExistsAsync(); BlobClient blob = InstrumentClient(containerClient.GetBlobClient(GetNewBlobName())); @@ -140,7 +140,7 @@ await TestHelper.AssertExpectedExceptionAsync( finally { // Clean up - await containerClient.DeleteAsync(); + await containerClient.DeleteIfExistsAsync(); } } @@ -203,7 +203,7 @@ public async Task Ctor_ConnectionString_Sas_Permissions_WriteOnly() try { // Act - await containerClient.CreateAsync(); + await containerClient.CreateIfNotExistsAsync(); BlobClient blob = InstrumentClient(containerClient.GetBlobClient(GetNewBlobName())); @@ -217,7 +217,7 @@ await TestHelper.AssertExpectedExceptionAsync( finally { // Clean up - await containerClient.DeleteAsync(); + await containerClient.DeleteIfExistsAsync(); } } private BlobContainerClient GetBlobContainerClient(string connectionString) => @@ -315,7 +315,7 @@ public async Task CreateAsync_WithSharedKey() } finally { - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } @@ -348,7 +348,7 @@ public async Task CreateAsync_WithSharedKey_Retry_RequestDateShouldUpdate() } finally { - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } @@ -370,7 +370,7 @@ public async Task CreateAsync_WithOauth() } finally { - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } @@ -392,7 +392,7 @@ public async Task CreateAsync_WithAccountSas() } finally { - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } @@ -420,7 +420,7 @@ public async Task CreateAsync_WithBlobServiceSas() { if (!pass) { - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } } @@ -441,7 +441,7 @@ public async Task CreateAsync_Metadata() AssertMetadataEquality(metadata, response.Value.Metadata); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -462,7 +462,7 @@ public async Task CreateAsync_EncryptionScopeOptions() await container.CreateAsync(encryptionScopeOptions: encryptionScopeOptions); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -480,7 +480,7 @@ public async Task CreateAsync_PublicAccess() Assert.AreEqual(PublicAccessType.Blob, response.Value.PublicAccess); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -490,7 +490,7 @@ public async Task CreateAsync_Error() BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); // ContainerUri is intentually created twice - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -498,7 +498,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("ContainerAlreadyExists", e.ErrorCode)); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -516,7 +516,7 @@ public async Task CreateIfNotExistsAsync() Assert.IsNotNull(response.Value.ETag); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -525,7 +525,7 @@ public async Task CreateIfNotExistsAsync_Exists() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); // Act await container.CreateIfNotExistsAsync(); @@ -535,7 +535,7 @@ public async Task CreateIfNotExistsAsync_Exists() Assert.IsNotNull(response.Value.ETag); // Cleanup - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -558,7 +558,7 @@ public async Task DeleteAsync() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); // Act Response response = await container.DeleteAsync(); @@ -589,7 +589,7 @@ public async Task DeleteAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); parameters.LeaseId = await SetupContainerLeaseCondition(container, parameters.LeaseId, garbageLeaseId); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, @@ -611,7 +611,7 @@ public async Task DeleteAsync_AccessConditions_Conditions_IfMatch_Should_Throw() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); var conditions = new BlobRequestConditions() { IfMatch = new ETag("etag") @@ -629,7 +629,7 @@ public async Task DeleteAsync_AccessConditions_Conditions_IfNoneMatch_Should_Thr // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); var conditions = new BlobRequestConditions() { IfNoneMatch = new ETag("etag") @@ -667,7 +667,7 @@ public async Task DeleteIfExistsAsync() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); // Act Response response = await container.DeleteIfExistsAsync(); @@ -699,7 +699,7 @@ public async Task ExistsAsync_Exists() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); // Act Response response = await container.ExistsAsync(); @@ -707,7 +707,7 @@ public async Task ExistsAsync_Exists() // Assert Assert.IsTrue(response.Value); - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } [Test] @@ -823,7 +823,7 @@ public async Task SetMetadataAsync_AccessConditions() { BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); parameters.LeaseId = await SetupContainerLeaseCondition(container, parameters.LeaseId, garbageLeaseId); IDictionary metadata = BuildMetadata(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( @@ -840,7 +840,7 @@ public async Task SetMetadataAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await container.DeleteAsync(new BlobRequestConditions { LeaseId = parameters.LeaseId }); + await container.DeleteIfExistsAsync(new BlobRequestConditions { LeaseId = parameters.LeaseId }); } } @@ -891,7 +891,7 @@ public async Task GetAccessPolicyAsync_Lease() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); var garbageLeaseId = GetGarbageLeaseId(); var leaseId = await SetupContainerLeaseCondition(container, ReceivedLeaseId, garbageLeaseId); var leaseAccessConditions = new BlobRequestConditions @@ -906,7 +906,7 @@ public async Task GetAccessPolicyAsync_Lease() Assert.IsNotNull(response); // Cleanup - await container.DeleteAsync(conditions: leaseAccessConditions); + await container.DeleteIfExistsAsync(conditions: leaseAccessConditions); } [Test] @@ -992,7 +992,7 @@ public async Task SetAccessPolicyAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); PublicAccessType publicAccessType = PublicAccessType.BlobContainer; BlobSignedIdentifier[] signedIdentifiers = BuildSignedIdentifiers(); parameters.LeaseId = await SetupContainerLeaseCondition(container, parameters.LeaseId, garbageLeaseId); @@ -1012,7 +1012,7 @@ public async Task SetAccessPolicyAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = parameters.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = parameters.LeaseId }); } } @@ -1047,7 +1047,7 @@ public async Task AcquireLeaseAsync() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); var id = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); @@ -1058,7 +1058,7 @@ public async Task AcquireLeaseAsync() Assert.AreEqual(id, response.Value.LeaseId); // Cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); } [Test] @@ -1099,7 +1099,7 @@ public async Task AcquireLeaseAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1117,7 +1117,7 @@ public async Task AcquireLeaseAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); } } @@ -1152,7 +1152,7 @@ public async Task RenewLeaseAsync() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); var id = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); @@ -1167,7 +1167,7 @@ public async Task RenewLeaseAsync() Assert.IsNotNull(renewResponse.GetRawResponse().Headers.RequestId); // Cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = renewResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = renewResponse.Value.LeaseId }); } [Test] @@ -1192,7 +1192,7 @@ public async Task RenewLeaseAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1210,7 +1210,7 @@ public async Task RenewLeaseAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); } } @@ -1222,7 +1222,7 @@ public async Task RenewLeaseAsync_AccessConditionsFail() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1240,7 +1240,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); } } @@ -1313,7 +1313,7 @@ public async Task ReleaseLeaseAsync_AccessConditionsFail() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1331,7 +1331,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); } } @@ -1377,7 +1377,7 @@ public async Task BreakLeaseAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, @@ -1397,7 +1397,7 @@ public async Task BreakLeaseAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); } } @@ -1409,7 +1409,7 @@ public async Task BreakLeaseAsync_AccessConditionsFail() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1427,7 +1427,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); } } @@ -1474,7 +1474,7 @@ public async Task ChangeLeaseAsync_AccessConditions() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, @@ -1496,7 +1496,7 @@ public async Task ChangeLeaseAsync_AccessConditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = response.Value.LeaseId }); } } @@ -1508,7 +1508,7 @@ public async Task ChangeLeaseAsync_AccessConditionsFail() // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(GetNewContainerName())); - await container.CreateAsync(); + await container.CreateIfNotExistsAsync(); BlobRequestConditions accessConditions = BuildContainerAccessConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1528,7 +1528,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await container.DeleteAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); + await container.DeleteIfExistsAsync(conditions: new BlobRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); } } @@ -2033,7 +2033,7 @@ public async Task ListContainersSegmentAsync_SecondaryStorageFirstRetrySuccessfu private async Task PerformSecondaryStorageTest(int numberOfReadFailuresToSimulate, bool retryOn404 = false) { BlobContainerClient containerClient = GetBlobContainerClient_SecondaryAccount_ReadEnabledOnRetry(numberOfReadFailuresToSimulate, out TestExceptionPolicy testExceptionPolicy, retryOn404); - await containerClient.CreateAsync(); + await containerClient.CreateIfNotExistsAsync(); Response properties = await EnsurePropagatedAsync( async () => await containerClient.GetPropertiesAsync(), @@ -2042,7 +2042,7 @@ private async Task PerformSecondaryStorageTest(int numberOf Assert.IsNotNull(properties); Assert.AreEqual(200, properties.GetRawResponse().Status); - await containerClient.DeleteAsync(); + await containerClient.DeleteIfExistsAsync(); return testExceptionPolicy; } #endregion diff --git a/sdk/storage/Azure.Storage.Common/tests/StorageSharedKeyCredentialsTests.cs b/sdk/storage/Azure.Storage.Common/tests/StorageSharedKeyCredentialsTests.cs index ccc4b324618c..8093ce3a1f6c 100644 --- a/sdk/storage/Azure.Storage.Common/tests/StorageSharedKeyCredentialsTests.cs +++ b/sdk/storage/Azure.Storage.Common/tests/StorageSharedKeyCredentialsTests.cs @@ -67,7 +67,8 @@ public async Task RollCredentialsToChildren() GetBlobOptions())); // Create a child container - BlobContainerClient container = await service.CreateBlobContainerAsync(GetNewContainerName()); + BlobContainerClient container = service.GetBlobContainerClient(GetNewContainerName()); + await container.CreateIfNotExistsAsync(); try { // Verify the credential works (i.e., doesn't throw) @@ -89,7 +90,7 @@ public async Task RollCredentialsToChildren() finally { // Clean up the child container - await container.DeleteAsync(); + await container.DeleteIfExistsAsync(); } } } From 28590d3101f25605fa4e2ad153efea5e07254470 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 26 Feb 2020 18:54:02 -0800 Subject: [PATCH 04/11] [AppendBlobClient] Use CreateIfNotExist() to improve test reliability --- .../tests/AppendBlobClientTests.cs | 52 +++++++++---------- .../tests/BlobBaseClientTests.cs | 12 ++--- .../tests/ContainerClientTests.cs | 20 +++---- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs index e9e46835235b..8cdcc8a56ef4 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs @@ -316,7 +316,7 @@ public async Task CreateIfNotExistsAsync_Exists() // Arrange var blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - Response response = await blob.CreateAsync(); + Response response = await blob.CreateIfNotExistsAsync(); // Act Response responseExists = await blob.CreateIfNotExistsAsync(); @@ -352,7 +352,7 @@ public async Task AppendBlockAsync() // Arrange var blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); const int blobSize = Constants.KB; var data = GetRandomBuffer(blobSize); @@ -381,7 +381,7 @@ public async Task AppendBlockAsync_CPK() CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); var data = GetRandomBuffer(Constants.KB); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act using var stream = new MemoryStream(data); @@ -403,7 +403,7 @@ public async Task AppendBlockAsync_EncryptionScope() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); var data = GetRandomBuffer(Constants.KB); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act using var stream = new MemoryStream(data); @@ -421,7 +421,7 @@ public async Task AppendBlockAsync_MD5() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); // Act @@ -443,7 +443,7 @@ public async Task AppendBlockAsync_MD5Fail() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); // Act @@ -496,7 +496,7 @@ public async Task AppendBlockAsync_AccessConditions() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); var data = GetRandomBuffer(7); parameters.Match = await SetupBlobMatchCondition(blob, parameters.Match); parameters.LeaseId = await SetupBlobLeaseCondition(blob, parameters.LeaseId, garbageLeaseId); @@ -540,7 +540,7 @@ public async Task AppendBlockAsync_AccessConditionsFail() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); var data = GetRandomBuffer(7); // AppendBlob needs to exists for us to test CreateAsync() with access conditions - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); parameters.NoneMatch = await SetupBlobMatchCondition(blob, parameters.NoneMatch); AppendBlobRequestConditions accessConditions = BuildDestinationAccessConditions( parameters: parameters, @@ -578,7 +578,7 @@ public async Task AppendBlockAsync_WithUnreliableConnection() AppendBlobClient blobFaulty = InstrumentClient(containerFaulty.GetAppendBlobClient(blobName)); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); var data = GetRandomBuffer(blobSize); var progressList = new List(); @@ -611,7 +611,7 @@ public async Task AppendBlockAsync_ProgressReporting() // Arrange var blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); const int blobSize = 4 * Constants.MB; var data = GetRandomBuffer(blobSize); TestProgress progress = new TestProgress(); @@ -641,11 +641,11 @@ public async Task AppendBlockFromUriAsync_Min() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act await destBlob.AppendBlockFromUriAsync(sourceBlob.Uri, new HttpRange(0, Constants.KB)); @@ -665,13 +665,13 @@ public async Task AppendBlockFromUriAsync_CPK() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); destBlob = InstrumentClient(destBlob.WithCustomerProvidedKey(customerProvidedKey)); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act Response response = await destBlob.AppendBlockFromUriAsync( @@ -696,12 +696,12 @@ public async Task AppendBlockFromUriAsync_EncryptionScope() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); destBlob = InstrumentClient(destBlob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act Response response = await destBlob.AppendBlockFromUriAsync( @@ -725,11 +725,11 @@ public async Task AppendBlockFromUriAsync_Range() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act await destBlob.AppendBlockFromUriAsync(sourceBlob.Uri, new HttpRange(2 * Constants.KB, 2 * Constants.KB)); @@ -756,11 +756,11 @@ public async Task AppendBlockFromUriAsync_MD5() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act await destBlob.AppendBlockFromUriAsync( @@ -782,11 +782,11 @@ public async Task AppendBlockFromUriAsync_MD5_Fail() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -829,11 +829,11 @@ public async Task AppendBlockFromUriAsync_AccessConditions() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); parameters.Match = await SetupBlobMatchCondition(destBlob, parameters.Match); parameters.SourceIfMatch = await SetupBlobMatchCondition(sourceBlob, parameters.SourceIfMatch); @@ -884,11 +884,11 @@ public async Task AppendBlockFromUriAsync_AccessConditionsFail() using (var stream = new MemoryStream(data)) { AppendBlobClient sourceBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(); + await sourceBlob.CreateIfNotExistsAsync(); await sourceBlob.AppendBlockAsync(stream); AppendBlobClient destBlob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(); + await destBlob.CreateIfNotExistsAsync(); parameters.NoneMatch = await SetupBlobMatchCondition(destBlob, parameters.NoneMatch); parameters.SourceIfNoneMatch = await SetupBlobMatchCondition(sourceBlob, parameters.SourceIfNoneMatch); diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs index febc5c99ac91..46e11d4a4b1c 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs @@ -1439,7 +1439,7 @@ public async Task GetPropertiesAsync_CPK() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act Response response = await blob.GetPropertiesAsync(); @@ -1457,7 +1457,7 @@ public async Task GetPropertiesAsync_EncryptionScope() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act Response response = await blob.GetPropertiesAsync(); @@ -1980,7 +1980,7 @@ public async Task SetMetadataAsync_CPK() CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); IDictionary metadata = BuildMetadata(); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act await blob.SetMetadataAsync(metadata); @@ -1995,7 +1995,7 @@ public async Task SetMetadataAsync_EncryptionScope() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); IDictionary metadata = BuildMetadata(); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act Response response = await blob.SetMetadataAsync(metadata); @@ -2088,7 +2088,7 @@ public async Task CreateSnapshotAsync_CPK() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act Response response = await blob.CreateSnapshotAsync(); @@ -2105,7 +2105,7 @@ public async Task CreateSnapshotAsync_EncryptionScope() await using DisposingContainer test = await GetTestContainerAsync(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act Response response = await blob.CreateSnapshotAsync(); diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs index eefc86fbad9c..a88eb90af225 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs @@ -1580,7 +1580,7 @@ public async Task ListBlobsFlatSegmentAsync_Metadata() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); IDictionary metadata = BuildMetadata(); - await blob.CreateAsync(metadata: metadata); + await blob.CreateIfNotExistsAsync(metadata: metadata); // Act IList blobs = await test.Container.GetBlobsAsync(traits: BlobTraits.Metadata).ToListAsync(); @@ -1599,7 +1599,7 @@ public async Task ListBlobsFlatSegmentAsync_EncryptionScope() AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act IList blobs = await test.Container.GetBlobsAsync().ToListAsync(); @@ -1620,8 +1620,8 @@ public async Task ListBlobsFlatSegmentAsync_Deleted() await EnableSoftDelete(); var blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - await blob.CreateAsync(); - await blob.DeleteAsync(); + await blob.CreateIfNotExistsAsync(); + await blob.DeleteIfExistsAsync(); // Act IList blobs = await test.Container.GetBlobsAsync(states: BlobStates.Deleted).ToListAsync(); @@ -1674,7 +1674,7 @@ public async Task ListBlobsFlatSegmentAsync_Snapshot() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); Response snapshotResponse = await blob.CreateSnapshotAsync(); // Act @@ -1800,7 +1800,7 @@ public async Task ListBlobsHierarchySegmentAsync_Metadata() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); IDictionary metadata = BuildMetadata(); - await blob.CreateAsync(metadata: metadata); + await blob.CreateIfNotExistsAsync(metadata: metadata); // Act BlobHierarchyItem item = await test.Container.GetBlobsByHierarchyAsync(traits: BlobTraits.Metadata).FirstAsync(); @@ -1818,7 +1818,7 @@ public async Task ListBlobsHierarchySegmentAsync_EncryptionScope() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); // Act BlobHierarchyItem item = await test.Container.GetBlobsByHierarchyAsync().FirstAsync(); @@ -1839,8 +1839,8 @@ public async Task ListBlobsHierarchySegmentAsync_Deleted() await EnableSoftDelete(); var blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); - await blob.CreateAsync(); - await blob.DeleteAsync(); + await blob.CreateIfNotExistsAsync(); + await blob.DeleteIfExistsAsync(); // Act IList blobs = await test.Container.GetBlobsByHierarchyAsync(states: BlobStates.Deleted).ToListAsync(); @@ -1893,7 +1893,7 @@ public async Task ListBlobsHierarchySegmentAsync_Snapshot() // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); - await blob.CreateAsync(); + await blob.CreateIfNotExistsAsync(); Response snapshotResponse = await blob.CreateSnapshotAsync(); // Act From 0fcd22c0ae3642066675b39b3462085f01c450a0 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 26 Feb 2020 18:58:00 -0800 Subject: [PATCH 05/11] [BlobBaseClient] Use DeleteIfExists() to improve test reliability --- sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs index 46e11d4a4b1c..b71d92b23220 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs @@ -1334,7 +1334,7 @@ public async Task UndeleteAsync() try { BlobBaseClient blob = await GetNewBlobClient(test.Container); - await blob.DeleteAsync(); + await blob.DeleteIfExistsAsync(); // Act Response response = await blob.UndeleteAsync(); From c3b59164745c479a24ba9bec3d4eaa5e19e3eb20 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 09:28:42 -0800 Subject: [PATCH 06/11] [PageBlobClient] Use CreateIfNotExists() to improve test reliability --- .../Azure.Storage.Blobs/tests/BlobTestBase.cs | 2 +- .../tests/PageBlobClientTests.cs | 46 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs index 957d30b8d30a..548dda43a4ec 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs @@ -377,7 +377,7 @@ private static string ToSasVersion(BlobClientOptions.ServiceVersion serviceVersi public async Task CreatePageBlobClientAsync(BlobContainerClient container, long size) { PageBlobClient blob = InstrumentClient(container.GetPageBlobClient(GetNewBlobName())); - await blob.CreateAsync(size, 0).ConfigureAwait(false); + await blob.CreateIfNotExistsAsync(size, 0).ConfigureAwait(false); return blob; } diff --git a/sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs index b3e801176af4..9a0b1cdf6879 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs @@ -347,7 +347,7 @@ public async Task UploadPagesAsync_CPK() CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); var data = GetRandomBuffer(Constants.KB); - await blob.CreateAsync(Constants.KB); + await blob.CreateIfNotExistsAsync(Constants.KB); using var stream = new MemoryStream(data); @@ -371,7 +371,7 @@ public async Task UploadPagesAsync_EncryptionScope() PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(blobName)); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); var data = GetRandomBuffer(Constants.KB); - await blob.CreateAsync(Constants.KB); + await blob.CreateIfNotExistsAsync(Constants.KB); using var stream = new MemoryStream(data); @@ -536,7 +536,7 @@ public async Task UploadPagesAsync_WithUnreliableConnection() PageBlobClient blobFaulty = InstrumentClient(containerClientFaulty.GetPageBlobClient(pageBlobName)); PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(pageBlobName)); - await blob.CreateAsync(blobSize) + await blob.CreateIfNotExistsAsync(blobSize) .ConfigureAwait(false); var offset = 0 * Constants.KB; @@ -627,7 +627,7 @@ public async Task ClearPagesAsync_CPK() PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); - await blob.CreateAsync(4 * Constants.KB); + await blob.CreateIfNotExistsAsync(4 * Constants.KB); var data = GetRandomBuffer(4 * Constants.KB); using (var stream = new MemoryStream(data)) { @@ -651,7 +651,7 @@ public async Task ClearPagesAsync_EncryptionScope() // Arrange PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(4 * Constants.KB); + await blob.CreateIfNotExistsAsync(4 * Constants.KB); var data = GetRandomBuffer(4 * Constants.KB); using (var stream = new MemoryStream(data)) { @@ -1250,7 +1250,7 @@ public async Task ResizeAsync_CPK() PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); blob = InstrumentClient(blob.WithCustomerProvidedKey(customerProvidedKey)); - await blob.CreateAsync(Constants.KB); + await blob.CreateIfNotExistsAsync(Constants.KB); var newSize = 8 * Constants.KB; // Act @@ -1269,7 +1269,7 @@ public async Task ResizeAsync_EncryptionScope() // Arrange PageBlobClient blob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); blob = InstrumentClient(blob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await blob.CreateAsync(Constants.KB); + await blob.CreateIfNotExistsAsync(Constants.KB); var newSize = 8 * Constants.KB; // Act @@ -1774,11 +1774,11 @@ public async Task UploadPagesFromUriAsync_Min() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); var range = new HttpRange(0, Constants.KB); // Act @@ -1801,13 +1801,13 @@ public async Task UploadPagesFromUriAsync_CPK() using var stream = new MemoryStream(data); PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); CustomerProvidedKey customerProvidedKey = GetCustomerProvidedKey(); destBlob = InstrumentClient(destBlob.WithCustomerProvidedKey(customerProvidedKey)); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); var range = new HttpRange(0, Constants.KB); // Act @@ -1833,12 +1833,12 @@ public async Task UploadPagesFromUriAsync_EncryptionScope() using var stream = new MemoryStream(data); PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); destBlob = InstrumentClient(destBlob.WithEncryptionScope(TestConfigDefault.EncryptionScope)); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); var range = new HttpRange(0, Constants.KB); // Act @@ -1864,11 +1864,11 @@ public async Task UploadPagesFromUriAsync_Range() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(4 * Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(4 * Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(2 * Constants.KB); + await destBlob.CreateIfNotExistsAsync(2 * Constants.KB); var range = new HttpRange(0, 2 * Constants.KB); // Act @@ -1899,11 +1899,11 @@ public async Task UploadPagesFromUriAsync_MD5() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); var range = new HttpRange(0, Constants.KB); // Act @@ -1928,11 +1928,11 @@ public async Task UploadPagesFromUriAsync_MD5_Fail() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); var range = new HttpRange(0, Constants.KB); // Act @@ -1981,11 +1981,11 @@ public async Task UploadPagesFromUriAsync_AccessConditions() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); parameters.Match = await SetupBlobMatchCondition(destBlob, parameters.Match); parameters.SourceIfMatch = await SetupBlobMatchCondition(sourceBlob, parameters.SourceIfMatch); @@ -2043,11 +2043,11 @@ public async Task UploadPagesFromUriAsync_AccessConditionsFail() using (var stream = new MemoryStream(data)) { PageBlobClient sourceBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await sourceBlob.CreateAsync(Constants.KB); + await sourceBlob.CreateIfNotExistsAsync(Constants.KB); await sourceBlob.UploadPagesAsync(stream, 0); PageBlobClient destBlob = InstrumentClient(test.Container.GetPageBlobClient(GetNewBlobName())); - await destBlob.CreateAsync(Constants.KB); + await destBlob.CreateIfNotExistsAsync(Constants.KB); parameters.NoneMatch = await SetupBlobMatchCondition(destBlob, parameters.NoneMatch); parameters.SourceIfNoneMatch = await SetupBlobMatchCondition(sourceBlob, parameters.SourceIfNoneMatch); From 0bb114a84adb44f37a767cfd2389caac0cfe77fc Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 09:33:12 -0800 Subject: [PATCH 07/11] [ShareClient] Use DeleteIfExists() to improve test reliability --- .../tests/FileTestBase.cs | 2 +- .../tests/ShareClientTests.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs index 592a917e0256..91270e6f249c 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs @@ -276,7 +276,7 @@ public async ValueTask DisposeAsync() { try { - await Share.DeleteAsync(true); + await Share.DeleteIfExistsAsync(true); Share = null; } catch diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs index c8d9c5d4079e..e2380f473c3c 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs @@ -113,8 +113,8 @@ async Task GetFileClient(ShareClient share) finally { // Clean up - await shareClient1.DeleteAsync(); - await shareClient2.DeleteAsync(); + await shareClient1.DeleteIfExistsAsync(); + await shareClient2.DeleteIfExistsAsync(); } } @@ -161,7 +161,7 @@ public async Task CreateAsync() } finally { - await share.DeleteAsync(false); + await share.DeleteIfExistsAsync(false); } } @@ -182,7 +182,7 @@ public async Task CreateAsync_Metadata() AssertMetadataEquality(metadata, response.Value.Metadata); // Cleanup - await share.DeleteAsync(false); + await share.DeleteIfExistsAsync(false); } [Test] @@ -202,7 +202,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("ShareAlreadyExists", e.ErrorCode)); // Cleanup - await share.DeleteAsync(false); + await share.DeleteIfExistsAsync(false); } [Test] @@ -220,7 +220,7 @@ public async Task CreateAsync_WithAccountSas() } finally { - await share.DeleteAsync(false); + await share.DeleteIfExistsAsync(false); } } @@ -248,7 +248,7 @@ await TestHelper.AssertExpectedExceptionAsync( { if (!pass) { - await share.DeleteAsync(); + await share.DeleteIfExistsAsync(); } } } @@ -315,7 +315,7 @@ public async Task CreateIfNotExistsAsync_NotExists() Assert.IsNotNull(response); // Cleanup - await share.DeleteAsync(); + await share.DeleteIfExistsAsync(); } [Test] @@ -334,7 +334,7 @@ public async Task CreateIfNotExistsAsync_Exists() Assert.IsNull(response); // Cleanup - await share.DeleteAsync(); + await share.DeleteIfExistsAsync(); } [Test] @@ -383,7 +383,7 @@ public async Task ExistsAsync_Exists() Assert.IsTrue(response.Value); // Cleanup - await share.DeleteAsync(); + await share.DeleteIfExistsAsync(); } [Test] From 3f22e905671747e94ae8a01169171aef21b568c2 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 09:44:43 -0800 Subject: [PATCH 08/11] [QueueClient] Use "Exists" APIs to improve test reliability --- .../tests/QueueClientTests.cs | 40 +++++++++---------- .../tests/QueueTestBase.cs | 4 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sdk/storage/Azure.Storage.Queues/tests/QueueClientTests.cs b/sdk/storage/Azure.Storage.Queues/tests/QueueClientTests.cs index bac2032a4c21..6334632b60c2 100644 --- a/sdk/storage/Azure.Storage.Queues/tests/QueueClientTests.cs +++ b/sdk/storage/Azure.Storage.Queues/tests/QueueClientTests.cs @@ -82,8 +82,8 @@ QueueClient GetClient(string connectionString) => try { // Act - await queueClient1.CreateAsync(); - await queueClient2.CreateAsync(); + await queueClient1.CreateIfNotExistsAsync(); + await queueClient2.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); @@ -97,8 +97,8 @@ QueueClient GetClient(string connectionString) => finally { // Clean up - await queueClient1.DeleteAsync(); - await queueClient2.DeleteAsync(); + await queueClient1.DeleteIfExistsAsync(); + await queueClient2.DeleteIfExistsAsync(); } } @@ -147,7 +147,7 @@ public async Task CreateAsync_WithSharedKey() } finally { - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } } @@ -190,7 +190,7 @@ public async Task CreateAsync_WithOauth() } finally { - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } } @@ -212,7 +212,7 @@ public async Task CreateAsync_WithAccountSas() } finally { - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } } @@ -242,7 +242,7 @@ public async Task CreateAsync_WithQueueServiceSas() { if (!pass) { - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } } } @@ -254,7 +254,7 @@ public async Task CreateAsync_Error() var queueName = GetNewQueueName(); QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(); + await queue.CreateIfNotExistsAsync(); // Act await TestHelper.AssertExpectedExceptionAsync( @@ -277,7 +277,7 @@ public async Task CreateIfNotExistsAsync_NotExists() Assert.IsNotNull(response); // Cleanup - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } [Test] @@ -287,7 +287,7 @@ public async Task CreateIfNotExistsAsync_Exists() var queueName = GetNewQueueName(); QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(); + await queue.CreateIfNotExistsAsync(); // Act Response response = await queue.CreateIfNotExistsAsync(); @@ -296,7 +296,7 @@ public async Task CreateIfNotExistsAsync_Exists() Assert.IsNull(response); // Cleanup - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } [Test] @@ -307,7 +307,7 @@ public async Task CreateIfNotExistsAsync_ExistsDifferentMetadata() QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(BuildMetadata()); + await queue.CreateIfNotExistsAsync(BuildMetadata()); // Act Response response = await queue.CreateIfNotExistsAsync(); @@ -316,7 +316,7 @@ public async Task CreateIfNotExistsAsync_ExistsDifferentMetadata() Assert.IsNull(response); // Cleanup - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } [Test] @@ -341,7 +341,7 @@ public async Task ExistsAsync_Exists() var queueName = GetNewQueueName(); QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(); + await queue.CreateIfNotExistsAsync(); // Act Response response = await queue.ExistsAsync(); @@ -350,7 +350,7 @@ public async Task ExistsAsync_Exists() Assert.IsTrue(response.Value); // Cleanup - await queue.DeleteAsync(); + await queue.DeleteIfExistsAsync(); } [Test] @@ -390,7 +390,7 @@ public async Task DeleteIfExistsAsync_Exists() var queueName = GetNewQueueName(); QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(); + await queue.CreateIfNotExistsAsync(); // Act Response response = await queue.DeleteIfExistsAsync(); @@ -462,7 +462,7 @@ await TestHelper.AssertExpectedExceptionAsync( public async Task GetPropertiesAsync_SecondaryStorage() { QueueClient queueClient = GetQueueClient_SecondaryAccount_ReadEnabledOnRetry(1, out TestExceptionPolicy testExceptionPolicy); - await queueClient.CreateAsync(); + await queueClient.CreateIfNotExistsAsync(); Response properties = await EnsurePropagatedAsync( async () => await queueClient.GetPropertiesAsync(), properties => properties.GetRawResponse().Status != 404); @@ -470,7 +470,7 @@ public async Task GetPropertiesAsync_SecondaryStorage() Assert.IsNotNull(properties); Assert.AreEqual(200, properties.GetRawResponse().Status); - await queueClient.DeleteAsync(); + await queueClient.DeleteIfExistsAsync(); AssertSecondaryStorageFirstRetrySuccessful(SecondaryStorageTenantPrimaryHost(), SecondaryStorageTenantSecondaryHost(), testExceptionPolicy); } #endregion @@ -590,7 +590,7 @@ public async Task DeleteAsync() var queueName = GetNewQueueName(); QueueServiceClient service = GetServiceClient_SharedKey(); QueueClient queue = InstrumentClient(service.GetQueueClient(queueName)); - await queue.CreateAsync(); + await queue.CreateIfNotExistsAsync(); // Act Response result = await queue.DeleteAsync(); diff --git a/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs b/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs index 44b18af4fa80..fad236770677 100644 --- a/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs +++ b/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs @@ -202,7 +202,7 @@ public class DisposingQueue : IAsyncDisposable public static async Task CreateAsync(QueueClient queue, IDictionary metadata) { - await queue.CreateAsync(metadata: metadata); + await queue.CreateIfNotExistsAsync(metadata: metadata); return new DisposingQueue(queue); } @@ -217,7 +217,7 @@ public async ValueTask DisposeAsync() { try { - await Queue.DeleteAsync(); + await Queue.DeleteIfExistsAsync(); Queue = null; } catch From 9172cdb886ea8f42adc5ea8469c64a5b59f2ebc6 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 09:55:24 -0800 Subject: [PATCH 09/11] [DataLakeFileSystemClient] Use "Exists" methods to improve test reliability --- .../tests/DataLakeTestBase.cs | 2 +- .../tests/FileSystemClientTests.cs | 76 +++++++++---------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs index 85bcee25a59e..85766f4d91e3 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs @@ -385,7 +385,7 @@ public async ValueTask DisposeAsync() { try { - await FileSystem.DeleteAsync(); + await FileSystem.DeleteIfExistsAsync(); FileSystem = null; } catch diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs index 52e848f819ba..b295e3cb1990 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs @@ -172,7 +172,7 @@ public async Task CreateAsync() } finally { - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } } @@ -194,7 +194,7 @@ public async Task CreateAsync_WithAccountSas() } finally { - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } } @@ -222,7 +222,7 @@ public async Task CreateAsync_WithDataLakeServiceSas() { if (!pass) { - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } } } @@ -249,7 +249,7 @@ public async Task CreateAsync_Oauth() } finally { - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } } @@ -269,7 +269,7 @@ public async Task CreateAsync_Metadata() AssertMetadataEquality(metadata, response.Value.Metadata); // Cleanup - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } [Test] @@ -287,7 +287,7 @@ public async Task CreateAsync_PublicAccess() Assert.AreEqual(Models.PublicAccessType.Path, response.Value.PublicAccess); // Cleanup - await fileSystem.DeleteAsync(); + await fileSystem.DeleteIfExistsAsync(); } [Test] @@ -305,7 +305,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("ContainerAlreadyExists", e.ErrorCode)); // Cleanup - await fileSystemClient.DeleteAsync(); + await fileSystemClient.DeleteIfExistsAsync(); } [Test] @@ -326,7 +326,7 @@ public async Task CreateIfNotExistAsync_NotExists() finally { // Cleanup - await fileSystemClient.DeleteAsync(); + await fileSystemClient.DeleteIfExistsAsync(); } } @@ -338,7 +338,7 @@ public async Task CreateIfNotExistAsync_Exists() DataLakeFileSystemClient fileSystemClient = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); try { - await fileSystemClient.CreateAsync(); + await fileSystemClient.CreateIfNotExistsAsync(); // Act Response response = await fileSystemClient.CreateIfNotExistsAsync(); @@ -349,7 +349,7 @@ public async Task CreateIfNotExistAsync_Exists() finally { // Cleanup - await fileSystemClient.DeleteAsync(); + await fileSystemClient.DeleteIfExistsAsync(); } } @@ -413,7 +413,7 @@ public async Task DeleteAsync() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); // Act Response response = await fileSystem.DeleteAsync(); @@ -444,7 +444,7 @@ public async Task DeleteAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); parameters.LeaseId = await SetupFileSystemLeaseCondition(fileSystem, parameters.LeaseId, garbageLeaseId); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, @@ -487,7 +487,7 @@ public async Task DeleteIfExistsAsync_Exists() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystemClient = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystemClient.CreateAsync(); + await fileSystemClient.CreateIfNotExistsAsync(); // Act Response response = await fileSystemClient.DeleteIfExistsAsync(); @@ -684,7 +684,7 @@ public async Task SetMetadataAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); parameters.LeaseId = await SetupFileSystemLeaseCondition(fileSystem, parameters.LeaseId, garbageLeaseId); IDictionary metadata = BuildMetadata(); DataLakeRequestConditions conditions = BuildFileSystemConditions( @@ -701,7 +701,7 @@ public async Task SetMetadataAsync_Conditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await fileSystem.DeleteAsync(new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(new DataLakeRequestConditions { LeaseId = parameters.LeaseId }); @@ -973,7 +973,7 @@ public async Task AquireLeaseAsync() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); var id = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); @@ -984,7 +984,7 @@ public async Task AquireLeaseAsync() Assert.AreEqual(id, response.Value.LeaseId); // Cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = response.Value.LeaseId }); @@ -1013,7 +1013,7 @@ public async Task AcquireLeaseAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1031,7 +1031,7 @@ public async Task AcquireLeaseAsync_Conditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = response.Value.LeaseId }); @@ -1069,7 +1069,7 @@ public async Task RenewLeaseAsync() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); var id = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); @@ -1084,7 +1084,7 @@ public async Task RenewLeaseAsync() Assert.IsNotNull(renewResponse.GetRawResponse().Headers.RequestId); // Cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = renewResponse.Value.LeaseId }); @@ -1112,7 +1112,7 @@ public async Task RenewLeaseAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1130,7 +1130,7 @@ public async Task RenewLeaseAsync_Conditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = response.Value.LeaseId }); @@ -1145,7 +1145,7 @@ public async Task RenewLeaseAsync_ConditionsFail() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1163,7 +1163,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); @@ -1239,7 +1239,7 @@ public async Task ReleaseLeaseAsync_ConditionsFail() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1257,7 +1257,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); @@ -1307,7 +1307,7 @@ public async Task ChangeLeaseAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, @@ -1329,7 +1329,7 @@ public async Task ChangeLeaseAsync_Conditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = response.Value.LeaseId }); @@ -1344,7 +1344,7 @@ public async Task ChangeLeaseAsync_ConditionsFail() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1364,7 +1364,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); @@ -1413,7 +1413,7 @@ public async Task BreakLeaseAsync_Conditions() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, @@ -1433,7 +1433,7 @@ public async Task BreakLeaseAsync_Conditions() Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); // Cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); @@ -1448,7 +1448,7 @@ public async Task BreakLeaseAsync_ConditionsFail() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, ifUnmodifiedSince: true, @@ -1466,7 +1466,7 @@ await TestHelper.AssertExpectedExceptionAsync( e => { }); // cleanup - await fileSystem.DeleteAsync(conditions: new DataLakeRequestConditions + await fileSystem.DeleteIfExistsAsync(conditions: new DataLakeRequestConditions { LeaseId = aquireLeaseResponse.Value.LeaseId }); @@ -1504,7 +1504,7 @@ public async Task GetAccessPolicy_Lease() // Arrange DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); string garbageLeaseId = GetGarbageLeaseId(); string leaseId = await SetupFileSystemLeaseCondition(fileSystem, ReceivedLeaseId, garbageLeaseId); DataLakeRequestConditions leaseAccessConditions = new DataLakeRequestConditions @@ -1520,7 +1520,7 @@ public async Task GetAccessPolicy_Lease() Assert.AreEqual(0, response.Value.SignedIdentifiers.Count()); // Cleanup - await fileSystem.DeleteAsync(conditions: leaseAccessConditions); + await fileSystem.DeleteIfExistsAsync(conditions: leaseAccessConditions); } [Test] @@ -1641,7 +1641,7 @@ public async Task SetAccessPolicyAsync_Conditions() DataLakeSignedIdentifier[] signedIdentifiers = BuildSignedIdentifiers(); DataLakeServiceClient service = GetServiceClient_SharedKey(); DataLakeFileSystemClient fileSystem = InstrumentClient(service.GetFileSystemClient(GetNewFileSystemName())); - await fileSystem.CreateAsync(); + await fileSystem.CreateIfNotExistsAsync(); DataLakeRequestConditions conditions = BuildFileSystemConditions( parameters: parameters, From 6e0c1612a88cfc3e123da0bf29c38efbe9b62078 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 12:46:18 -0800 Subject: [PATCH 10/11] [DataLakeDirectoryClient] Use CreateIfNotExists() to improve test reliability --- .../tests/DirectoryClientTests.cs | 12 ++++++------ .../tests/FileSystemClientTests.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs index 2eb2fbb30e54..bd273e58a997 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs @@ -292,7 +292,7 @@ public async Task CreateIfNotExistsAsync_Exists() // Arrange await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.CreateIfNotExistsAsync(); @@ -321,7 +321,7 @@ public async Task ExistsAsync_Exists() // Arrange await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.ExistsAsync(); @@ -364,7 +364,7 @@ public async Task DeleteIfExists_Exists() // Arrange await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(GetNewDirectoryName())); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.DeleteIfExistsAsync(); @@ -412,7 +412,7 @@ public async Task DeleteAsync() // Arrange var name = GetNewDirectoryName(); DataLakeDirectoryClient directory = InstrumentClient(test.FileSystem.GetDirectoryClient(name)); - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); // Act Response response = await directory.DeleteAsync(); @@ -1144,7 +1144,7 @@ public async Task GetPropertiesAsync_PathSasWithIdentifiers() await using DisposingFileSystem test = await GetNewFileSystem(fileSystemName: fileSystemName); DataLakeDirectoryClient directoryClient = InstrumentClient(test.FileSystem.GetDirectoryClient(directoryName)); - await directoryClient.CreateAsync(); + await directoryClient.CreateIfNotExistsAsync(); DataLakeSignedIdentifier signedIdentifier = new DataLakeSignedIdentifier { @@ -1767,7 +1767,7 @@ public async Task DeleteSubDirectoryAsync() // Arrange string directoryName = GetNewDirectoryName(); DataLakeDirectoryClient directoryClient = directory.GetSubDirectoryClient(directoryName); - await directoryClient.CreateAsync(); + await directoryClient.CreateIfNotExistsAsync(); // Assert await directory.DeleteFileAsync(directoryName); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs index b295e3cb1990..1748362ac8d7 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs @@ -1759,7 +1759,7 @@ private async Task SetUpFileSystemForListing(DataLakeFileSystemClient fileSystem { DataLakeDirectoryClient directory = InstrumentClient(fileSystem.GetDirectoryClient(pathNames[i])); directories[i] = directory; - await directory.CreateAsync(); + await directory.CreateIfNotExistsAsync(); } } From b4834c7440a93ffddcb811137650f2e90365fb60 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Thu, 27 Feb 2020 12:55:27 -0800 Subject: [PATCH 11/11] [DataLakeFileClient] Use CreateIfNotExists() to improve test reliability --- .../tests/DirectoryClientTests.cs | 2 +- .../tests/FileClientTests.cs | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs index bd273e58a997..0fefb8b88f8b 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs @@ -1584,7 +1584,7 @@ public async Task DeleteFileAsync() // Arrange string fileName = GetNewFileName(); DataLakeFileClient fileClient = directory.GetFileClient(fileName); - await fileClient.CreateAsync(); + await fileClient.CreateIfNotExistsAsync(); // Assert await directory.DeleteFileAsync(fileName); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs index abb7809475e3..576c8f03ff97 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs @@ -300,7 +300,7 @@ public async Task CreateIfNotExistsAsync_Exists() await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName()); DataLakeFileClient file = InstrumentClient(directory.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); // Act Response response = await file.CreateIfNotExistsAsync(); @@ -331,7 +331,7 @@ public async Task ExistsAsync_Exists() await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName()); DataLakeFileClient file = InstrumentClient(directory.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); // Act Response response = await file.ExistsAsync(); @@ -377,7 +377,7 @@ public async Task DeleteIfExists_Exists() await using DisposingFileSystem test = await GetNewFileSystem(); DataLakeDirectoryClient directory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName()); DataLakeFileClient file = InstrumentClient(directory.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); // Act Response response = await file.DeleteIfExistsAsync(); @@ -1481,7 +1481,7 @@ public async Task AppendDataAsync() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); // Act @@ -1522,7 +1522,7 @@ public async Task AppendDataAsync_ProgressReporting() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); TestProgress progress = new TestProgress(); @@ -1546,7 +1546,7 @@ public async Task AppendDataAsync_ContentHash() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); byte[] contentHash = MD5.Create().ComputeHash(data); @@ -1582,7 +1582,7 @@ public async Task AppendDataAsync_Position() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data0 = GetRandomBuffer(Constants.KB); var data1 = GetRandomBuffer(Constants.KB); @@ -1612,7 +1612,7 @@ public async Task AppendDataAsync_Lease() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); var leaseId = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); @@ -1632,7 +1632,7 @@ public async Task AppendDataAsync_InvalidLease() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); // Act @@ -1651,7 +1651,7 @@ public async Task AppendDataAsync_NullStream_Error() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); // Act using (var stream = (MemoryStream)null) @@ -1673,7 +1673,7 @@ public async Task FlushDataAsync() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); using (var stream = new MemoryStream(data)) @@ -1695,7 +1695,7 @@ public async Task FlushDataAsync_HttpHeaders() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); byte[] data = GetRandomBuffer(Constants.KB); byte[] contentHash = MD5.Create().ComputeHash(data); PathHttpHeaders headers = new PathHttpHeaders @@ -1733,7 +1733,7 @@ public async Task FlushDataAsync_Position() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); using (var stream = new MemoryStream(data)) @@ -1755,7 +1755,7 @@ public async Task FlushDataAsync_RetainUncommittedData() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); using (var stream = new MemoryStream(data)) @@ -1777,7 +1777,7 @@ public async Task FlushDataAsync_Close() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); using (var stream = new MemoryStream(data)) @@ -1802,7 +1802,7 @@ public async Task FlushDataAsync_Conditions() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Constants.KB); using (var stream = new MemoryStream(data)) @@ -1831,7 +1831,7 @@ public async Task FlushDataAsync_ConditionsFail() // Arrange DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); - await file.CreateAsync(); + await file.CreateIfNotExistsAsync(); var data = GetRandomBuffer(Size); using (var stream = new MemoryStream(data))