Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage][DataMovement] Remove the sync WaitForCompletion for now #47774

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.DataMovement.Blobs/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.DataMovement.Blobs",
"Tag": "net/storage/Azure.Storage.DataMovement.Blobs_acf7c63811"
"Tag": "net/storage/Azure.Storage.DataMovement.Blobs_3132ba5d1c"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.DataMovement.Files.Shares",
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_6238d37ed0"
"Tag": "net/storage/Azure.Storage.DataMovement.Files.Shares_91bd99f1ca"
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ internal TransferOperation() { }
public Azure.Storage.DataMovement.TransferStatus Status { get { throw null; } }
public Azure.Storage.DataMovement.TransferManager TransferManager { get { throw null; } }
public virtual System.Threading.Tasks.Task PauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public void WaitForCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
public System.Threading.Tasks.Task WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class TransferOptions : System.IEquatable<Azure.Storage.DataMovement.TransferOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ internal TransferOperation() { }
public Azure.Storage.DataMovement.TransferStatus Status { get { throw null; } }
public Azure.Storage.DataMovement.TransferManager TransferManager { get { throw null; } }
public virtual System.Threading.Tasks.Task PauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public void WaitForCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
public System.Threading.Tasks.Task WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class TransferOptions : System.IEquatable<Azure.Storage.DataMovement.TransferOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ internal TransferOperation() { }
public Azure.Storage.DataMovement.TransferStatus Status { get { throw null; } }
public Azure.Storage.DataMovement.TransferManager TransferManager { get { throw null; } }
public virtual System.Threading.Tasks.Task PauseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public void WaitForCompletion(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { }
public System.Threading.Tasks.Task WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class TransferOptions : System.IEquatable<Azure.Storage.DataMovement.TransferOptions>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.DataMovement/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.DataMovement",
"Tag": "net/storage/Azure.Storage.DataMovement_03db2933f4"
"Tag": "net/storage/Azure.Storage.DataMovement_80d90a8906"
}
16 changes: 3 additions & 13 deletions sdk/storage/Azure.Storage.DataMovement/src/TransferOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,7 @@ internal TransferOperation(
}

/// <summary>
/// Ensures completion of the TransferOperation and attempts to get result
/// </summary>
public void WaitForCompletion(CancellationToken cancellationToken = default)
{
#pragma warning disable AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
WaitForCompletionAsync(cancellationToken).GetAwaiter().GetResult();
#pragma warning restore AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
}

/// <summary>
/// Waits until the data transfer itself has completed
/// Waits until the transfer has completed.
/// </summary>
/// <param name="cancellationToken"></param>
public async Task WaitForCompletionAsync(CancellationToken cancellationToken = default)
Expand All @@ -80,11 +70,11 @@ public async Task WaitForCompletionAsync(CancellationToken cancellationToken = d
}

/// <summary>
/// Attempts to pause the current Data Transfer.
/// Attempts to pause the current transfer.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>
/// Will return false if the data transfer has already been completed.
/// Will return false if the transfer has already been completed.
///
/// Will return true if the pause has taken place.
/// </returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,119 +832,6 @@ await TestTransferWithTimeout.WaitForCompletionAsync(
Assert.AreEqual(true, transfer.Status.HasSkippedItems);
}

[RecordedTest]
public async Task StartTransfer_EnsureCompleted()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

TransferOptions options = new TransferOptions();
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

// Create transfer to do a EnsureCompleted
TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
concurrency: 1,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
await testEventsRaised.AssertSingleCompletedCheck();
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
}

[RecordedTest]
public async Task StartTransfer_EnsureCompleted_Failed()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

TransferOptions options = new TransferOptions()
{
CreationPreference = StorageResourceCreationPreference.FailIfExists
};
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

// Create transfer to do a AwaitCompletion
TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
concurrency: 1,
createFailedCondition: true,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
await testEventsRaised.AssertSingleFailedCheck(1);
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
Assert.AreEqual(true, transfer.Status.HasFailedItems);
var testException = testEventsRaised.FailedEvents.First().Exception;
if (testException is RequestFailedException rfe)
{
Assert.That(rfe.ErrorCode, Does.Contain(_expectedOverwriteExceptionMessage));
}
else
{
Assert.IsTrue(testException.Message.Contains(_expectedOverwriteExceptionMessage));
}
}

[RecordedTest]
public async Task StartTransfer_EnsureCompleted_Skipped()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

// Create transfer options with Skipping available
TransferOptions options = new TransferOptions()
{
CreationPreference = StorageResourceCreationPreference.SkipIfExists
};
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

// Create transfer to do a EnsureCompleted
TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
concurrency: 1,
createFailedCondition: true,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
await testEventsRaised.AssertSingleSkippedCheck();
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
Assert.AreEqual(true, transfer.Status.HasSkippedItems);
}

private async Task CopyRemoteObjects_VerifyProperties(
TSourceContainerClient sourceContainer,
TDestinationContainerClient destinationContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,115 +793,9 @@ await TestTransferWithTimeout.WaitForCompletionAsync(
await testEventsRaised.AssertContainerCompletedWithSkippedCheck(1);
}

[RecordedTest]
public async Task StartTransfer_EnsureCompleted()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

// Create transfer to do a EnsureCompleted
TransferOptions options = new TransferOptions();
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
1,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
testEventsRaised.AssertUnexpectedFailureCheck();
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
}

[Test]
[LiveOnly] // https://github.com/Azure/azure-sdk-for-net/issues/46717
public async Task StartTransfer_EnsureCompleted_Failed()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

TransferOptions options = new TransferOptions()
{
CreationPreference = StorageResourceCreationPreference.FailIfExists
};
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

// Create transfer to do a AwaitCompletion
TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
1,
createFailedCondition: true,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
Assert.AreEqual(true, transfer.Status.HasFailedItems);
await testEventsRaised.AssertContainerCompletedWithFailedCheck(1);
Assert.IsTrue(testEventsRaised.FailedEvents.First().Exception.Message.Contains(_expectedOverwriteExceptionMessage));
}

[RecordedTest]
public async Task StartTransfer_EnsureCompleted_Skipped()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
await using IDisposingContainer<TDestinationContainerClient> destination = await GetDestinationDisposingContainerAsync();

// Create transfer options with Skipping available
TransferOptions options = new TransferOptions()
{
CreationPreference = StorageResourceCreationPreference.SkipIfExists
};
TestEventsRaised testEventsRaised = new TestEventsRaised(options);

// Create transfer to do a EnsureCompleted
TransferOperation transfer = await CreateStartTransfer(
source.Container,
destination.Container,
1,
createFailedCondition: true,
options: options);

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
TestTransferWithTimeout.WaitForCompletion(
transfer,
testEventsRaised,
cancellationTokenSource.Token);

// Assert
testEventsRaised.AssertUnexpectedFailureCheck();
Assert.NotNull(transfer);
Assert.IsTrue(transfer.HasCompleted);
Assert.AreEqual(TransferState.Completed, transfer.Status.State);
Assert.AreEqual(true, transfer.Status.HasSkippedItems);
}

[Test]
[LiveOnly] // https://github.com/Azure/azure-sdk-for-net/issues/46717
public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks()
public async Task StartTransfer_AwaitCompletion_Failed_SmallChunks()
{
// Arrange
await using IDisposingContainer<TSourceContainerClient> source = await GetSourceDisposingContainerAsync();
Expand All @@ -926,7 +820,7 @@ public async Task StartTransfer_EnsureCompleted_Failed_SmallChunks()

// Act
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
TestTransferWithTimeout.WaitForCompletion(
await TestTransferWithTimeout.WaitForCompletionAsync(
transfer,
testEventsRaised,
cancellationTokenSource.Token);
Expand Down
Loading
Loading