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

Feature/storage/open write page blob bug #14716

Merged
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
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.6.0-preview.1 (Unreleased)
- Fixed bug where BlobClient.Upload(), BlockBlobClient.Upload(), AppendBlobClient.AppendBlock(), and PageBlobClient.UploadPages() would deadlock if the content stream's position was not 0.
- Fixed bug in BlobBaseClient.OpenRead() causing us to do more download called than necessary.
- Fixed bug where PageBlobWriteStream would advance Position 2x the number of written bytes.

## 12.5.1 (2020-08-18)
- Fixed bug in TaskExtensions.EnsureCompleted method that causes it to unconditionally throw an exception in the environments with synchronization context
Expand Down
1 change: 0 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/PageBlobWriteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ await WriteToBufferInternal(
}
}
}
_position += count;
}

protected override async Task AppendInternal(bool async, CancellationToken cancellationToken)
Expand Down
41 changes: 41 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,47 @@ await TestHelper.CatchAsync<Exception>(
}
}

[Test]
public async Task OpenWriteAsync_Position()
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
PageBlobClient blob = await CreatePageBlobClientAsync(test.Container, Constants.KB);

byte[] data0 = GetRandomBuffer(512);
byte[] data1 = GetRandomBuffer(512);
Comment on lines +3394 to +3395
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we parametrize this test and try let's say 1, 2 and 5 pages ?

using Stream dataStream0 = new MemoryStream(data0);
using Stream dataStream1 = new MemoryStream(data1);
byte[] expectedData = new byte[Constants.KB];
Array.Copy(data0, expectedData, 512);
Array.Copy(data1, 0, expectedData, 512, 512);

// Act
Stream openWriteStream = await blob.OpenWriteAsync(
overwrite: false,
position: 0);

Assert.AreEqual(0, openWriteStream.Position);

await dataStream0.CopyToAsync(openWriteStream);

Assert.AreEqual(512, openWriteStream.Position);

await dataStream1.CopyToAsync(openWriteStream);

Assert.AreEqual(1024, openWriteStream.Position);

await openWriteStream.FlushAsync();

Assert.AreEqual(1024, openWriteStream.Position);

Response<BlobDownloadInfo> result = await blob.DownloadAsync();
MemoryStream dataResult = new MemoryStream();
await result.Value.Content.CopyToAsync(dataResult);
Assert.AreEqual(expectedData.Length, dataResult.Length);
TestHelper.AssertSequenceEqual(expectedData, dataResult.ToArray());
}

private PageBlobRequestConditions BuildAccessConditions(
AccessConditionParameters parameters,
bool lease = false,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading