Skip to content

Commit 94939dc

Browse files
authored
fix(playwrighttesting): await upload buffer method (Azure#47056)
* fix(playwrighttesting): await upload buffer method * chore(): move to upload buffer sync --------- Co-authored-by: Siddharth Singha Roy <[email protected]>
1 parent f962fe1 commit 94939dc

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Implementation/BlobService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public async Task UploadBufferAsync(string uri, string buffer, string fileRelati
3535
_logger.Error($"Failed to upload buffer: {ex}");
3636
}
3737
}
38+
39+
public void UploadBuffer(string uri, string buffer, string fileRelativePath)
40+
{
41+
try
42+
{
43+
string cloudFilePath = GetCloudFilePath(uri, fileRelativePath);
44+
BlobClient blobClient = new(new Uri(cloudFilePath));
45+
byte[] bufferBytes = Encoding.UTF8.GetBytes(buffer);
46+
blobClient.Upload(new BinaryData(bufferBytes), overwrite: true);
47+
_logger.Info($"Uploaded buffer to {fileRelativePath}");
48+
}
49+
catch (Exception ex)
50+
{
51+
_logger.Error($"Failed to upload buffer: {ex}");
52+
}
53+
}
54+
3855
public void UploadBlobFile(string uri, string fileRelativePath, string filePath)
3956
{
4057
string cloudFilePath = GetCloudFilePath(uri, fileRelativePath);

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Interface/IBlobService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ internal interface IBlobService
1414
/// <param name="fileRelativePath"></param>
1515
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
1616
Task UploadBufferAsync(string uri, string buffer, string fileRelativePath);
17-
string GetCloudFilePath(string uri, string fileRelativePath);
17+
void UploadBuffer(string uri, string buffer, string fileRelativePath);
18+
string GetCloudFilePath(string uri, string fileRelativePath);
1819
void UploadBlobFile(string uri, string fileRelativePath, string filePath);
1920
public string? GetCloudFileName(string filePath, string testExecutionId);
2021
}

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/TestProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Text.Json;
1010
using System.Threading.Tasks;
11+
using Azure.Core.Pipeline;
1112
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation;
1213
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface;
1314
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Model;
@@ -174,7 +175,7 @@ public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e)
174175
// Upload rawResult to blob storage using sasUri
175176
var rawTestResultJson = JsonSerializer.Serialize(rawResult);
176177
var filePath = $"{testResult.TestExecutionId}/rawTestResult.json";
177-
_blobService.UploadBufferAsync(sasUri!.Uri!, rawTestResultJson, filePath);
178+
_blobService.UploadBuffer(sasUri!.Uri!, rawTestResultJson, filePath);
178179
}
179180
else
180181
{

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Implementation/BlobServiceTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ public async Task UploadBufferAsync_WithException_LogsError()
3535
_loggerMock!.Verify(logger => logger.Error(It.IsAny<string>()), Times.Once);
3636
}
3737

38+
[Test]
39+
public void UploadBuffer_WithException_LogsError()
40+
{
41+
string uri = "invalid_uri";
42+
string buffer = "Test buffer";
43+
string fileRelativePath = "test/path";
44+
45+
_blobService!.UploadBuffer(uri, buffer, fileRelativePath);
46+
47+
_loggerMock!.Verify(logger => logger.Error(It.IsAny<string>()), Times.Once);
48+
}
49+
3850
[Test]
3951
public void GetCloudFilePath_WithValidParameters_ReturnsCorrectPath()
4052
{

0 commit comments

Comments
 (0)