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
30 changes: 29 additions & 1 deletion .github/instructions/ado-pipelines.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,45 @@ Test partitioning:
- `TestSet=AE` — Always Encrypted tests (controlled by `runAlwaysEncryptedTests`)

Test filters — default excludes `failing` and `flaky` categories:
- `failing` — known permanent failures, always excluded
- `failing` — known failures or platform-ineligible tests, always excluded from CI
- `flaky` — intermittent failures, quarantined in separate pipeline steps
- `nonnetfxtests` / `nonnetcoreapptests` — platform-specific exclusions
- `nonwindowstests` / `nonlinuxtests` — OS-specific exclusions

Flaky test quarantine:
- Quarantined tests (`[Trait("category", "flaky")]`) run in separate steps after main tests
- Quarantine filters use `category=flaky&category!=failing`
- Main test runs are not blocked by flaky failures
- No code coverage collected for flaky runs
- Configured in `common/templates/steps/build-and-run-tests-netcore-step.yml`, `build-and-run-tests-netfx-step.yml`, and `run-all-tests-step.yml`

### Platform-specific exclusions depend on runner filters

The `Microsoft.DotNet.XUnitExtensions` version used by this repository implements
`[PlatformSpecific]` as a trait-based exclusion, **not an automatic skip**. During
discovery, its discoverer adds `category=failing` on a nonmatching platform. On a
matching platform, it adds no `failing` trait of its own. The runner must exclude
`failing`; the attribute alone does not prevent execution.

Categories are additive. For example, a Windows-only test also marked
`[Trait("category", "flaky")]` has `flaky` on Windows, but both `flaky` and `failing`
on Linux/macOS. A filter of `category=flaky` still selects it on Linux/macOS.
The resulting failure can be an unsupported API, such as distributed transaction
promotion throwing `PlatformNotSupportedException`, rather than a product regression.

Keep platform exclusions in **every regular and quarantine CI filter**:

- Regular: `category!=failing&category!=flaky&category!=interactive`
- Quarantine: `category=flaky&category!=failing`

An explicit `TestFilters` or `--filter` replaces the default category exclusions;
it does not extend them. A `TestSet` restriction or unsigned-test exclusion does
not restore the missing platform guard. Do not assume that excluding `flaky` in
regular runs also protects quarantine runs. Filtered-out tests are not executed
or reported as skipped.

### SNI and test timeouts

SNI testing — `useManagedSNI` controls testing with native SNI (`false`) or managed SNI (`true`)

Test timeout — `--blame-hang-timeout 10m` (configured in `build.proj` and threaded through CI test steps); tests exceeding 10 minutes are killed
Expand Down
34 changes: 32 additions & 2 deletions .github/instructions/testing.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,42 @@ Use `[Trait("category", "...")]` (xUnit, used in both ManualTests and UnitTests)
| `nonwindowstests` | Windows | Test targets non-Windows behavior |
| `nonlinuxtests` | Linux | Test targets non-Linux behavior |
| `nonuaptests` | UAP/UWP | Not applicable for UAP |
| `failing` | All platforms | Known permanent failures |
| `failing` | Wherever the trait is present | Known failures or platform-ineligible tests |
| `flaky` | All platforms (quarantine) | Intermittently failing tests (see Quarantine Zone below) |
| `probation` | With `flaky` (quarantine) | Fixed tests being monitored before leaving quarantine |

### PlatformSpecific Is a Trait-Based Exclusion, Not a Skip

In the `Microsoft.DotNet.XUnitExtensions` version used by this repository,
`[PlatformSpecific(TestPlatforms.Windows)]` does not directly skip a test on
Linux/macOS. Its discoverer adds `category=failing` on a nonmatching platform,
and the runner must explicitly filter that category out. On Windows, the
attribute adds no `failing` trait of its own. This differs from a failing
`ConditionalFact` condition, which marks a test skipped.

A test can have several values for the same category. If the Windows-only test
also has `[Trait("category", "flaky")]`, it has both `flaky` and `failing` on
Linux/macOS. Selecting `category=flaky` alone therefore runs the unsupported test.
Use `category=flaky&category!=failing` for quarantine runs: the test remains
eligible on Windows but is excluded on Linux/macOS.

The default regular-suite filter already excludes `failing`. However, an explicit
`TestFilters` or `dotnet test --filter` expression replaces the default category
exclusions rather than adding to them. Include `category!=failing` when narrowing
normal or quarantine runs, including fully-qualified-name filters. Omit it only
when deliberately investigating an excluded test and after checking its platform
requirements. `TestFilters=none` also removes this platform protection; test-set
selection and actual conditional skips are separate mechanisms.

Do not interpret every `failing` trait as a product defect: it can be generated
because the current platform is unsupported. Filtered-out tests do not run and
are not reported as skipped.

### Flaky Test Quarantine Zone
Tests that intermittently fail are quarantined with `[Trait("category", "flaky")]`. Quarantined tests:
- Are **excluded** from regular test runs by the default filter: `category!=failing&category!=flaky`
- Run in **separate quarantine pipeline steps** to track their status without blocking CI
- Use `category=flaky&category!=failing` so platform-ineligible cases stay excluded
- Do **not** collect code coverage
- Should be investigated and fixed, then un-quarantined by removing the trait

Expand Down Expand Up @@ -139,6 +167,8 @@ The default test filter is defined in `build.proj` via `TestFilters`:
<TestFilters Condition="'$(TestFilters)' == ''">category!=failing&amp;category!=flaky&amp;category!=interactive</TestFilters>
```
This can be overridden via build property: `dotnet build build.proj -t:TestSqlClientUnit -p:TestFilters="your_filter"`.
Retain `category!=failing` in custom filters unless intentionally overriding the
trait-based platform exclusion described above.

### Test Attributes
```csharp
Expand Down Expand Up @@ -188,7 +218,7 @@ dotnet test "src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.S
--filter "category!=failing&category!=flaky&category!=interactive"

# Run ONLY quarantined flaky tests (for investigation)
dotnet test ... --filter "category=flaky"
dotnet test ... --filter "category=flaky&category!=failing"

# Single test
dotnet test ... --filter "FullyQualifiedName=Namespace.ClassName.MethodName"
Expand Down
43 changes: 38 additions & 5 deletions TESTGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Keep retry/error/partner assertions explicit; transport attempt counts are not p

The simulator runs blocking handlers on dedicated workers. Fault budgets are reserved before
response processing, and disposal must finish owned workers and report unexpected handler failures.
The scheduler-sensitive `SsrpClientTests` share the nonparallel `SimulatedServerTestCollection`.
Their UDP response assertions must not compete with unrelated blocking collections for thread-pool
completion workers during the transport's one-second receive timeout. This isolation does not change
the exclusive scheduler used by the regression or increase production timeouts.
Transport initialization and socket closure share a lock so shutdown cannot invalidate a
`TcpClient` while its worker acquires the stream or initializes the parser. The worker-drain
wait stays outside that lock, allowing a stopped worker to finish its cleanup.
Expand Down Expand Up @@ -247,29 +251,58 @@ big-endian runtime (for example, s390x). Passing on x64 verifies only the little

| Category | Why it is excluded by default |
|---------------|-------------------------------------------------------------------------------------|
| `failing` | Known failing tests. |
| `failing` | Known failing tests or tests excluded on the current platform by `PlatformSpecific`. |
| `flaky` | Intermittently failing tests. |
| `interactive` | Tests that require user interaction or external setup not suitable for normal runs. |

Unsigned runs also exclude `category=signed`, unless `TestFilters=none` is specified. An explicit
`TestFilters` expression replaces the default `failing`, `flaky`, and `interactive` exclusions, so include
any you still want to exclude. Trait keys must match the source: use lowercase `category` and uppercase `Set`.

Examples:
### PlatformSpecific does not automatically skip tests

The `Microsoft.DotNet.XUnitExtensions` version used here implements
`[PlatformSpecific]` through traits. For example,
`[PlatformSpecific(TestPlatforms.Windows)]` adds `category=failing` during discovery
on Linux/macOS, rather than marking the test skipped. On Windows it adds no
`failing` trait of its own. The attribute relies on the runner filtering out
`category=failing`; without that filter, the test can execute on an unsupported
platform.

This is particularly important for quarantined tests. A Windows-only test marked
`[Trait("category", "flaky")]` has both category values, `flaky` and `failing`,
on Linux/macOS. `category=flaky` selects it despite the platform restriction.
Use `category=flaky&category!=failing` to run eligible quarantined tests while
preserving platform exclusions. Otherwise, an unsupported operation can fail
with `PlatformNotSupportedException` and look like a driver regression.

Regular runs use `category!=failing&category!=flaky&category!=interactive`.
Custom filters replace these exclusions, so retain `category!=failing` even when
selecting a single test by name, unless deliberately investigating an excluded
test on an appropriate platform. `TestFilters=none` removes the trait-based
platform guard too. Test-set restrictions do not restore it.

This mechanism differs from `ConditionalFact` conditions that actually skip tests.
Filtered-out tests are not executed or reported as skipped, and a generated
`failing` trait does not by itself indicate a product defect.

### Filter examples

Run a single test by fully-qualified name:

```bash
dotnet build -t:TestSqlClientUnit -p:TestFramework=net10.0 -p:TestFilters=FullyQualifiedName=Namespace.ClassName.MethodName
dotnet build -t:TestSqlClientUnit -p:TestFramework=net10.0 \
'-p:TestFilters=category!=failing&FullyQualifiedName=Namespace.ClassName.MethodName'
```

Run only flaky tests while investigating quarantine failures:

```bash
dotnet build -t:TestSqlClientManual -p:TestFramework=net10.0 -p:TestFilters=category=flaky
dotnet build -t:TestSqlClientManual -p:TestFramework=net10.0 \
'-p:TestFilters=category=flaky&category!=failing'
```

Disable the default filter:
Disable the default filter, including trait-based platform exclusions, for deliberate investigation:

```bash
dotnet build -t:TestSqlClientFunctional -p:TestFramework=net10.0 -p:TestFilters=none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ steps:
-p:SqlClientPackageVersion=${{ parameters.packageVersion }}
--no-build
-v n
--filter "category=flaky"
--filter "category=flaky&category!=failing"
--blame-hang
--blame-hang-dump-type full
--blame-hang-timeout 10m
Expand Down Expand Up @@ -111,7 +111,7 @@ steps:
-p:SqlClientPackageVersion=${{ parameters.packageVersion }}
--no-build
-v n
--filter "category=flaky"
--filter "category=flaky&category!=failing"
--blame-hang
--blame-hang-dump-type full
--blame-hang-timeout 10m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ steps:
-p:SqlClientPackageVersion=${{ parameters.packageVersion }}
--no-build
-v n
--filter "category=flaky"
--filter "category=flaky&category!=failing"
--blame-hang
--blame-hang-dump-type full
--blame-hang-timeout 10m
Expand Down Expand Up @@ -111,7 +111,7 @@ steps:
-p:SqlClientPackageVersion=${{ parameters.packageVersion }}
--no-build
-v n
--filter "category=flaky"
--filter "category=flaky&category!=failing"
--blame-hang
--blame-hang-dump-type full
--blame-hang-timeout 10m
Expand Down
18 changes: 9 additions & 9 deletions eng/pipelines/common/templates/steps/run-all-tests-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the intention of the change is to avoid running failing tests in the Flaky tests step. Failing would always fail so not excluding them in the first place with Flaky tests was a wrong choice, is that correct ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two unexpected things converged here:

  • We, as test authors, never intended to have the "flaky" and "failing" traits applied to a test at the same time - it's one or the other, so the filters never accounted for that.
  • The XUnitExtensions [PlatformSpecific] attribute injects a "failing" trait onto tests whose required platform doesn't match the runtime. Yowzers!

The surprising [PlatformSpecific] implementation coufounded our original assumption, and now we must explicitly exclude "failing" everywhere, because it no longer means "tests we explicitly marked as failing". It has been expanded to include "tests that shouldn't run on this platform". Perhaps upgrading to xUnit3 will help with situations like this since it has a richer filtering engine.

-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
${{ else }}: # x86
Expand All @@ -130,7 +130,7 @@ steps:
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:DotnetPath=${{ parameters.dotnetx86RootPath }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
Expand Down Expand Up @@ -175,7 +175,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
${{ else }}: # x86
Expand All @@ -187,7 +187,7 @@ steps:
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:DotnetPath=${{ parameters.dotnetx86RootPath }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
Expand Down Expand Up @@ -245,7 +245,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
${{ else }}: # x86
Expand All @@ -258,7 +258,7 @@ steps:
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:DotnetPath=${{ parameters.dotnetx86RootPath }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
Expand Down Expand Up @@ -292,7 +292,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
Expand Down Expand Up @@ -325,7 +325,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
Expand Down Expand Up @@ -360,7 +360,7 @@ steps:
-p:Configuration=${{ parameters.buildConfiguration }}
-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
-p:TestResultsFolderPath=TestResults
-p:TestCodeCoverage=false
continueOnError: true
23 changes: 23 additions & 0 deletions eng/pipelines/scripts/tests/Pipeline-Platforms.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,27 @@ Describe 'Unified PR platform selection' {
$platform.Groups[1].Value | Should -BeIn @('Windows', 'Linux')
}
}

}

Describe 'Quarantine platform filtering in <RelativePath>' -ForEach @(
@{ RelativePath = 'common/templates/steps/run-all-tests-step.yml' }
@{ RelativePath = 'common/templates/steps/build-and-run-tests-netcore-step.yml' }
@{ RelativePath = 'common/templates/steps/build-and-run-tests-netfx-step.yml' }
) {
It 'excludes platform-ineligible tests even when they are also flaky' {
# Arrange
$pipelineRoot = Join-Path $PSScriptRoot '../..'
$template = Get-Content -LiteralPath (Join-Path $pipelineRoot $RelativePath) -Raw

# Act
$filters = [regex]::Matches(
$template, '(?:-p:TestFilters=|--filter )"([^"]*category=flaky[^"]*)"')

# Assert
$filters.Count | Should -BeGreaterThan 0
foreach ($filter in $filters) {
$filter.Groups[1].Value | Should -Match '(^|&)category!=failing(&|$)'
}
}
}
2 changes: 1 addition & 1 deletion eng/pipelines/scripts/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Add `-Output Detailed` to see per-test results.
| `Open-LocalizationPr.Tests.ps1` | `Open-LocalizationPr.ps1` — de-duplication of the scheduled localization pull request. |
| `Install-DockerCli.macos.Tests.ps1` | `Install-DockerCli.macos.ps1` — Homebrew bottle selection for the macOS docker CLI. |
| `Pipeline-Arguments.Tests.ps1` | PR build/pack/test argument quoting and the repository's CI variable naming convention. |
| `Pipeline-Platforms.Tests.ps1` | Windows/Linux-only PR validation, macOS job/dependency exclusion, and unchanged CI macOS defaults. |
| `Pipeline-Platforms.Tests.ps1` | Windows/Linux-only PR validation, macOS job/dependency exclusion, unchanged CI macOS defaults, and platform-ineligible test exclusion in quarantine filters. |
| `Pipeline-XmlDocs.Tests.ps1` | Parallel PR XML documentation validation and parameterized, retry-safe pack artifact routing. |
| `Build-Orchestration.Tests.ps1` | Explicit root/standalone PowerShell module restore, MSBuild test filters, dependency-pack ordering/version forwarding, local restore freshness, and generated argument quoting. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private static async Task AuthenticateAsClientAsync(SslStream sslStream, string
ClientCertificates = certificate,
RemoteCertificateValidationCallback = validationCallback
};
await sslStream.AuthenticateAsClientAsync(sslClientOptions, token);
// Strict opens synchronously wait for this task, even on single-worker schedulers.
await sslStream.AuthenticateAsClientAsync(sslClientOptions, token).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ private static SsrpResult SendUDPRequest(IPAddress[] ipAddresses, int port, byte
for (int i = 0; i < ipAddresses.Length; i++)
{
IPEndPoint endPoint = new IPEndPoint(ipAddresses[i], port);
tasks.Add(Task.Factory.StartNew<SsrpResult>(() => SendUDPRequest(endPoint, requestPacket), cts.Token));
// The caller blocks below, so request workers must not inherit its scheduler.
tasks.Add(Task.Factory.StartNew<SsrpResult>(
() => SendUDPRequest(endPoint, requestPacket),
cts.Token, TaskCreationOptions.None, TaskScheduler.Default));
}

List<Task<SsrpResult>> completedTasks = new();
Expand Down
Loading
Loading