Skip to content

Commit

Permalink
Fixing download 304 tests again. (Azure#33425)
Browse files Browse the repository at this point in the history
* Fix for Download 304 live tests

* Removing mistake test
  • Loading branch information
amnguye authored Jan 17, 2023
1 parent e215b40 commit 69f8c40
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 70 deletions.
16 changes: 8 additions & 8 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,14 +1553,14 @@ public async Task DownloadTo_Initial304()
uploadResponse = await blob.UploadAsync(stream);
}

CheckModifiedSinceAndWait(uploadResponse);
DateTimeOffset modifiedSince = CheckModifiedSinceAndWait(uploadResponse);

// Add conditions to cause a failure and ensure we don't explode
Response result = await blob.DownloadToAsync(
Stream.Null,
new BlobRequestConditions
{
IfModifiedSince = Recording.UtcNow
IfModifiedSince = modifiedSince
});
Assert.AreEqual(304, result.Status);
}
Expand All @@ -1580,14 +1580,14 @@ public async Task DownloadContent_Initial304()
uploadResponse = await blob.UploadAsync(stream);
}

CheckModifiedSinceAndWait(uploadResponse);
DateTimeOffset modifiedSince = CheckModifiedSinceAndWait(uploadResponse);

// Add conditions to cause a failure and ensure we don't explode
Response<BlobDownloadResult> result = await blob.DownloadContentAsync(new BlobDownloadOptions
{
Conditions = new BlobRequestConditions
{
IfModifiedSince = Recording.UtcNow
IfModifiedSince = modifiedSince
}
});
Assert.AreEqual(304, result.GetRawResponse().Status);
Expand All @@ -1608,14 +1608,14 @@ public async Task DownloadStreaming_Initial304()
uploadResponse = await blob.UploadAsync(stream);
}

CheckModifiedSinceAndWait(uploadResponse);
DateTimeOffset modifiedSince = CheckModifiedSinceAndWait(uploadResponse);

// Add conditions to cause a failure and ensure we don't explode
Response<BlobDownloadStreamingResult> result = await blob.DownloadStreamingAsync(new BlobDownloadOptions
{
Conditions = new BlobRequestConditions
{
IfModifiedSince = Recording.UtcNow
IfModifiedSince = modifiedSince
}
});
Assert.AreEqual(304, result.GetRawResponse().Status);
Expand All @@ -1636,13 +1636,13 @@ public async Task Download_Initial304()
uploadResponse = await blob.UploadAsync(stream);
}

CheckModifiedSinceAndWait(uploadResponse);
DateTimeOffset modifiedSince = CheckModifiedSinceAndWait(uploadResponse);

// Add conditions to cause a failure and ensure we don't explode
Response<BlobDownloadInfo> result = await blob.DownloadAsync(
conditions: new BlobRequestConditions
{
IfModifiedSince = Recording.UtcNow
IfModifiedSince = modifiedSince
});
Assert.AreEqual(304, result.GetRawResponse().Status);
}
Expand Down
6 changes: 5 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,17 @@ public void Handle(BlobQueryError blobQueryError)
///
/// At most it's a 1 second difference wait. But most of the time there's no wait.
/// </summary>
public void CheckModifiedSinceAndWait(Response<BlobContentInfo> uploadResponse)
/// <returns>Returns the time the IfModifiedSince should be for the Download Request to cause a 304</returns>
public DateTimeOffset CheckModifiedSinceAndWait(Response<BlobContentInfo> uploadResponse)
{
DateTimeOffset offsetNow = Recording.UtcNow;
if (DateTimeOffset.Compare(uploadResponse.Value.LastModified, offsetNow) > 0)
{
// Wait the difference plus 2 second
Thread.Sleep(uploadResponse.Value.LastModified.Subtract(offsetNow));
offsetNow = uploadResponse.Value.LastModified;
}
return offsetNow;
}
}
}

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

0 comments on commit 69f8c40

Please sign in to comment.