Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ internal sealed record AzureDevOpsTestCaseResult(
[property: JsonPropertyName("startedDate")] DateTimeOffset? StartedDate,
[property: JsonPropertyName("completedDate")] DateTimeOffset? CompletedDate)
{
/// <summary>
/// Gets the terminal state of the test result.
/// </summary>
/// <remarks>
/// Azure DevOps does not infer this from <see cref="Outcome"/>. Omitting it leaves the result in
/// <c>Pending</c> even after the containing run is completed.
/// </remarks>
[JsonPropertyName("state")]
public string State { get; } = AzureDevOpsLivePublishingConstants.CompletedTestRunState;

/// <summary>
/// Gets the id Azure DevOps assigned to this result, set only when updating an already published result.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsTestCaseResult.State.get -> string!
Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsTestResultsClient.AzureDevOpsTestResultsClient(Microsoft.Testing.Platform.Helpers.ITask! task, Microsoft.Testing.Platform.Helpers.IClock! clock, Microsoft.Testing.Platform.Logging.ILoggerFactory! loggerFactory) -> void
Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsTestResultsClient.AzureDevOpsTestResultsClient(System.Net.Http.HttpClient! httpClient, Microsoft.Testing.Platform.Helpers.ITask! task, Microsoft.Testing.Platform.Helpers.IClock! clock, Microsoft.Testing.Platform.Logging.ILogger? logger) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ function gatewayMain() {
createRunRequests: 0,
createRunStates: [],
publishedTestOutcomes: [],
publishedTestStates: [],
attachments: [],
patchedStates: [],
authorizedRequests: 0,
Expand Down Expand Up @@ -679,6 +680,7 @@ function gatewayMain() {
count: results.length,
value: results.map((result, index) => {
summary.publishedTestOutcomes.push(result.testCaseTitle + '=' + result.outcome);
summary.publishedTestStates.push(result.testCaseTitle + '=' + (result.state ?? '<missing>'));
return { id: 5000 + index, automatedTestName: result.automatedTestName };
}),
});
Expand Down Expand Up @@ -1241,13 +1243,19 @@ public async Task BrowserWasmExecution_AzureDevOpsLivePublishingReachesStubbedRe
root.GetProperty("patchedStates").EnumerateArray().Select(static element => element.GetString()).ToArray(),
combined);

// Both tests are published with their real outcomes, and the run ends with the
// "at least one test failed" exit code (so the publisher did not swallow the failure).
// Both tests are published with their real outcomes and terminal states, and the run ends with
// the "at least one test failed" exit code (so the publisher did not swallow the failure).
Assert.AreEqual((int)ExitCode.AtLeastOneTestFailed, root.GetProperty("exitCode").GetInt32(), combined);
string[] publishedTestOutcomes = [.. root.GetProperty("publishedTestOutcomes").EnumerateArray().Select(static element => element.GetString()!)];
Assert.ContainsSingle(publishedTestOutcomes.Where(static outcome => outcome == "PassingTest=Passed"), combined);
Assert.ContainsSingle(publishedTestOutcomes.Where(static outcome => outcome == "FailingTestWithAttachment=Failed"), combined);

// Regression for https://github.com/microsoft/testfx/issues/11122: a terminal outcome does not
// transition the Azure DevOps result out of Pending unless the result-level state is also sent.
string[] publishedTestStates = [.. root.GetProperty("publishedTestStates").EnumerateArray().Select(static element => element.GetString()!)];
Assert.ContainsSingle(publishedTestStates.Where(static state => state == "PassingTest=Completed"), combined);
Assert.ContainsSingle(publishedTestStates.Where(static state => state == "FailingTestWithAttachment=Completed"), combined);

// The file-backed attachment proves TryBuildAttachmentRequest reads from the wasm virtual
// filesystem and base64-encodes the real bytes; the inline console attachments come from the
// failing test's captured output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,20 @@ public void CreateTestCaseResult_MapsMtpStatesToAzdoResults()
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete

Assert.AreEqual(AzureDevOpsLivePublishingConstants.PassedTestOutcome, passed?.Outcome);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, passed?.State);
Assert.AreEqual(2000L, passed?.DurationInMs);
Assert.AreEqual(startTime, passed?.StartedDate);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.FailedTestOutcome, failed?.Outcome);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, failed?.State);
Assert.AreEqual("boom", failed?.ErrorMessage);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.NotExecutedTestOutcome, skipped?.Outcome);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, skipped?.State);
Assert.AreEqual("skip", skipped?.ErrorMessage);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.FailedTestOutcome, timeout?.Outcome);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, timeout?.State);
Assert.AreEqual("Timeout: too slow", timeout?.ErrorMessage);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.AbortedTestOutcome, cancelled?.Outcome);
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, cancelled?.State);
Assert.AreEqual("stopped", cancelled?.ErrorMessage);
}

Expand Down Expand Up @@ -4035,6 +4040,7 @@ public async Task AzureDevOpsTestResultsClient_UpdateTestResults_PatchesRerunAnd
JsonElement result = document.RootElement[0];
Assert.AreEqual(777, result.GetProperty("id").GetInt32());
Assert.AreEqual("rerun", result.GetProperty("resultGroupType").GetString());
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, result.GetProperty("state").GetString());
Assert.AreEqual(AzureDevOpsLivePublishingConstants.PassedTestOutcome, result.GetProperty("outcome").GetString());
Assert.AreEqual(JsonValueKind.Null, result.GetProperty("errorMessage").ValueKind);
Assert.AreEqual(JsonValueKind.Null, result.GetProperty("stackTrace").ValueKind);
Expand Down Expand Up @@ -4450,6 +4456,7 @@ public async Task AzureDevOpsTestResultsClient_PublishTestResults_OmitsRerunFiel

using var document = JsonDocument.Parse(capturedBody!);
JsonElement created = document.RootElement[0];
Assert.AreEqual(AzureDevOpsLivePublishingConstants.CompletedTestRunState, created.GetProperty("state").GetString());
Assert.IsFalse(created.TryGetProperty("id", out _));
Assert.IsFalse(created.TryGetProperty("resultGroupType", out _));
Assert.IsFalse(created.TryGetProperty("subResults", out _));
Expand Down