Skip to content
Open
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 @@ -9,7 +9,6 @@
using Microsoft.Testing.Platform.Extensions.TestHost;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.IPC.Models;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.Services;

namespace Microsoft.Testing.Extensions.Policy;
Expand Down Expand Up @@ -47,14 +46,20 @@ public async Task ConsumeAsync(IDataProducer dataProducer, IData value, Cancella
return;
}

if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeFailedProperties, nodeState.GetType()) != -1)
if (nodeState is FailedTestNodeStateProperty or ErrorTestNodeStateProperty
#pragma warning disable CS0618, MTP0001 // Type or member is obsolete
or TimeoutTestNodeStateProperty or CancelledTestNodeStateProperty)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[Nit] Pragma scope is one token too wide

TimeoutTestNodeStateProperty is not marked [Obsolete] — only CancelledTestNodeStateProperty carries MTP0001. Both other files in this PR scope the pragma correctly:

// AbortForMaxFailedTestsExtension.cs (correct)
if (testNodeStateProperty is FailedTestNodeStateProperty or ErrorTestNodeStateProperty
        or TimeoutTestNodeStateProperty       // ← outside the disabled region
#pragma warning disable CS0618, MTP0001
        or CancelledTestNodeStateProperty
#pragma warning restore CS0618, MTP0001

The same pattern should be applied here (move TimeoutTestNodeStateProperty above the disable pragma). No functional impact — an unnecessary suppress is harmless — but it sets a misleading precedent and will hide a real CS0618 warning if TimeoutTestNodeStateProperty becomes obsolete later without the pragma being removed.

Recommendation: Split the line so TimeoutTestNodeStateProperty is outside the disabled region, matching the style in AbortForMaxFailedTestsExtension.cs:

if (nodeState is FailedTestNodeStateProperty or ErrorTestNodeStateProperty
    or TimeoutTestNodeStateProperty
#pragma warning disable CS0618, MTP0001 // Type or member is obsolete
    or CancelledTestNodeStateProperty)
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete

(Same change applies to the second if block on lines 60–62.)

#pragma warning restore CS0618, MTP0001 // Type or member is obsolete
{
ApplicationStateGuard.Ensure(_retryFailedTestsLifecycleCallbacks is not null);
ApplicationStateGuard.Ensure(_retryFailedTestsLifecycleCallbacks.Client is not null);
await _retryFailedTestsLifecycleCallbacks.Client.RequestReplyAsync<FailedTestRequest, VoidResponse>(new FailedTestRequest(testNodeUpdateMessage.TestNode.Uid), cancellationToken).ConfigureAwait(false);
}

if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeProperties, nodeState.GetType()) != -1)
if (nodeState is PassedTestNodeStateProperty or FailedTestNodeStateProperty or ErrorTestNodeStateProperty
#pragma warning disable CS0618, MTP0001 // Type or member is obsolete
or TimeoutTestNodeStateProperty or CancelledTestNodeStateProperty)
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete
{
_totalTests++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.Resources;
using Microsoft.Testing.Platform.Services;

Expand Down Expand Up @@ -67,8 +66,12 @@ public async Task ConsumeAsync(IDataProducer dataProducer, IData value, Cancella
return;
}

if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeFailedProperties, testNodeStateProperty.GetType()) != -1 &&
++_failCount >= _maxFailedTests.Value &&
if (testNodeStateProperty is FailedTestNodeStateProperty or ErrorTestNodeStateProperty
or TimeoutTestNodeStateProperty
#pragma warning disable CS0618, MTP0001 // Type or member is obsolete
or CancelledTestNodeStateProperty
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete
&& ++_failCount >= _maxFailedTests.Value &&
// If already triggered, don't do it again.
!_policiesService.IsMaxFailedTestsTriggered)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.OutputDevice;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.OutputDevice;
using Microsoft.Testing.Platform.Resources;
using Microsoft.Testing.Platform.Telemetry;
Expand Down Expand Up @@ -80,10 +79,17 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
{
case DiscoveredTestNodeStateProperty:
_openTelemetryResultHandler?.NotifyDiscovered();
// In discovery mode, discovered tests count toward the "ran" total.
if (_isDiscovery)
{
_totalRanTests++;
}

break;

case PassedTestNodeStateProperty passed:
_openTelemetryResultHandler?.NotifyPassed(message.TestNode, passed);
_totalRanTests++;
break;

case FailedTestNodeStateProperty:
Expand All @@ -93,10 +99,23 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
case CancelledTestNodeStateProperty:
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete
_openTelemetryResultHandler?.NotifyFailed(message.TestNode, executionState);
_failedTestsCount++;
_totalRanTests++;
break;

case SkippedTestNodeStateProperty skipped:
_openTelemetryResultHandler?.NotifySkipped(message.TestNode, skipped);
// DESIGN: Skipped tests are intentionally excluded from `_totalRanTests`.
// An all-skipped (or zero-test) run leaves `_totalRanTests == 0` and yields exit code
// `ExitCode.ZeroTests` (8) in `GetProcessExitCode`. This is the strict default chosen in
// #3216 / #3243 ("Skipped tests count as not run") to surface the common "invalid filter
// ran nothing" mistake. The documented opt-out for users who legitimately expect
// all-skipped runs is `--ignore-exit-code 8`.
//
// Two other layers mirror this decision and must stay in lockstep:
// - TerminalTestReporter.Summary.cs (`allTestsWereSkipped`)
// - Microsoft.Testing.Platform.MSBuild InvokeTestingPlatformTask (run-summary verdict)
// Do not relax this without revisiting those sites and the design discussion above.
break;

case InProgressTestNodeStateProperty:
Expand All @@ -108,34 +127,6 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
break;
}

Type outcomeType = executionState.GetType();
if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeFailedProperties, outcomeType) != -1)
{
_failedTestsCount++;
}

if (_isDiscovery
&& Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeDiscoveredProperties, outcomeType) != -1)
{
_totalRanTests++;
}

// DESIGN: Skipped tests are intentionally excluded from `_totalRanTests`.
// `WellKnownTestNodeTestRunOutcomeProperties` does not contain `SkippedTestNodeStateProperty`, so an
// all-skipped (or zero-test) run leaves `_totalRanTests == 0` and yields exit code `ExitCode.ZeroTests` (8)
// in `GetProcessExitCode`. This is the strict default chosen in #3216 / #3243 ("Skipped tests count as not
// run") to surface the common "invalid filter ran nothing" mistake. The documented opt-out for users who
// legitimately expect all-skipped runs is `--ignore-exit-code 8`.
//
// Two other layers mirror this decision and must stay in lockstep:
// - TerminalTestReporter.Summary.cs (`allTestsWereSkipped`)
// - Microsoft.Testing.Platform.MSBuild InvokeTestingPlatformTask (run-summary verdict)
// Do not relax this without revisiting those sites and the design discussion above.
else if (Array.IndexOf(TestNodePropertiesCategories.WellKnownTestNodeTestRunOutcomeProperties, outcomeType) != -1)
{
_totalRanTests++;
}

return Task.CompletedTask;
}

Expand Down
Loading