Skip to content

Commit

Permalink
Run PR validation tests on windows (#7909)
Browse files Browse the repository at this point in the history
* [CI] Enable tests to run on Windows for PR validation

- Adjust the github workflow to handle building, and running on linux,
  and windows
* Disable docker tests on windows when running on github actions because nested containers are not supported
* Simplify os name showed in github checks

* Add IsWindows, IsLinux to PlatformDetection to enable combining them with IsRunningOn

* Disable test AppHostExitsWhenCliProcessPidDies
* Disable failing windows tests on github actions
* Disable failing Dashboard tests on github actions
* Disable failing Hosting.Testing tests on github actions

* Sort list of test classes

Co-authored-by: Dan Moseley <[email protected]>
  • Loading branch information
radical and danmoseley authored Mar 6, 2025
1 parent 173dd9e commit 0ae0f0b
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 51 deletions.
100 changes: 59 additions & 41 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,76 +22,99 @@ on:

jobs:

_:
runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
name: linux
dotnet_script: ./dotnet.sh
build_script: ./build.sh
- os: windows-latest
name: windows
dotnet_script: .\dotnet.cmd
build_script: .\build.cmd
timeout-minutes: 60
name: ${{ inputs.testShortName }}
name: ${{ matrix.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Trust HTTPS development certificate
run: ./dotnet.sh dev-certs https --trust
if: matrix.os == 'ubuntu-latest'
run: ${{ matrix.dotnet_script }} dev-certs https --trust

- name: Verify Docker is running
# nested docker containers not supported on windows
if: matrix.os == 'ubuntu-latest'
run: docker info

- name: Install Azure Functions Core Tools
if: inputs.testShortName == 'Playground' || inputs.testShortName == 'Azure'
if: matrix.os == 'ubuntu-latest' && (inputs.testShortName == 'Playground' || inputs.testShortName == 'Azure')
run: |
sudo apt-get update
sudo apt-get install -y azure-functions-core-tools-4
- name: Compute test project path
id: compute_project_path
shell: pwsh
env:
CI: false
# Convert the shortname of the test to a project path in tests/
run: |
export OPTION_A=${{ github.workspace }}/tests/Aspire.${{ inputs.testShortName }}.Tests/Aspire.${{ inputs.testShortName }}.Tests.csproj; \
export OPTION_B=${{ github.workspace }}/tests/${{ inputs.testShortName }}.Tests/${{ inputs.testShortName }}.Tests.csproj; \
echo TEST_PROJECT_PATH=$(test -f $OPTION_A && echo $OPTION_A || echo $OPTION_B); \
echo TEST_PROJECT_PATH=$(test -f $OPTION_A && echo $OPTION_A || echo $OPTION_B) >> $GITHUB_ENV
$testShortName = "${{ inputs.testShortName }}"
$projectPath1 = "${{ github.workspace }}/tests/$testShortName.Tests/$testShortName.Tests.csproj"
$projectPath2 = "${{ github.workspace }}/tests/Aspire.$testShortName.Tests/Aspire.$testShortName.Tests.csproj"
if (Test-Path -Path $projectPath1) {
$projectPath = $projectPath1
} elseif (Test-Path -Path $projectPath2) {
$projectPath = $projectPath2
} else {
Write-Error "No matching project path found."
exit 1
}
echo "TEST_PROJECT_PATH=$projectPath" >> $env:GITHUB_ENV
- name: Build test project
id: build_t
env:
CI: false
run: |
./build.sh -restore -ci -build -projects $TEST_PROJECT_PATH
${{ matrix.build_script }} -restore -ci -build -projects ${{ env.TEST_PROJECT_PATH }}
# Workaround for bug in Azure Functions Worker SDK. See https://github.com/Azure/azure-functions-dotnet-worker/issues/2969.
- name: Rebuild for Azure Functions project
if: inputs.testShortName == 'Playground'
env:
CI: false
run: |
./dotnet.sh build ${{ github.workspace }}/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/AzureFunctionsEndToEnd.Functions.csproj /p:SkipUnstableEmulators=true
${{ matrix.dotnet_script }} build ${{ github.workspace }}/playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.Functions/AzureFunctionsEndToEnd.Functions.csproj /p:SkipUnstableEmulators=true
- name: Run tests
id: run-tests
env:
CI: false
DCP_DIAGNOSTICS_LOG_LEVEL: debug
DCP_DIAGNOSTICS_LOG_FOLDER: ${{ github.workspace }}/testresults/dcp
run: |
./dotnet.sh test $TEST_PROJECT_PATH \
/p:ContinuousIntegrationBuild=true \
-s eng/testing/.runsettings \
--logger "console;verbosity=normal" \
--logger "trx" \
--logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" \
--blame \
--blame-hang-timeout ${{ inputs.testHangTimeout }} \
--blame-crash \
--results-directory testresults \
--no-restore \
--no-build \
${{ inputs.extraTestArgs }} \
-- \
RunConfiguration.CollectSourceInformation=true \
RunConfiguration.TestSessionTimeout=${{ inputs.testSessionTimeoutMs }}
run: >
${{ matrix.dotnet_script }} test ${{ env.TEST_PROJECT_PATH }}
/p:ContinuousIntegrationBuild=true
-s eng/testing/.runsettings
-l "console;verbosity=normal"
-l "trx"
-l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
"--blame"
--blame-hang-timeout ${{ inputs.testHangTimeout }}
--blame-crash
--results-directory testresults
--no-restore
--no-build
${{ inputs.extraTestArgs }}
--
RunConfiguration.CollectSourceInformation=true
RunConfiguration.TestSessionTimeout=${{ inputs.testSessionTimeoutMs }}
# Save the result of the previous steps - success or failure
# in the form of a file result-success/result-failure -{name}.rst
Expand All @@ -107,7 +130,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: test-job-result-${{ inputs.testShortName }}
name: test-job-result-${{ inputs.testShortName }}-${{ matrix.os }}
path: result-*.rst

- name: Dump docker info
Expand All @@ -118,16 +141,11 @@ jobs:
docker volume ls
docker network ls
- name: Upload bin log artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: binlog-${{ inputs.testShortName }}
path: "**/*.binlog"

- name: Upload test results artifact
- name: Upload logs, and test results
if: always()
uses: actions/upload-artifact@v4
with:
name: testresults-${{ inputs.testShortName }}
path: testresults/**
name: logs-${{ inputs.testShortName }}-${{ matrix.os }}
path: |
**/*.binlog
testresults/**
38 changes: 29 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration Tests
name: Integration

on:
pull_request:
Expand All @@ -12,25 +12,45 @@ concurrency:

jobs:
setup_for_tests:
name: Get test projects to run
runs-on: ubuntu-latest
name: Enumerate test projects (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
dotnet_script: ./dotnet.sh
- os: windows-latest
dotnet_script: .\dotnet.cmd
outputs:
tests_matrix: ${{ steps.generate_test_matrix.outputs.tests_matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get list of tests
env:
CI: false
run: >
${{ matrix.dotnet_script }} build ${{ github.workspace }}/tests/Shared/GetTestProjects.proj
/p:TestsListOutputPath=${{ github.workspace }}/artifacts/TestsForGithubActions.list
/p:ContinuousIntegrationBuild=true
- name: Generate tests matrix
id: generate_test_matrix
shell: pwsh
env:
CI: false
run: |
./dotnet.sh build ${{ github.workspace }}/tests/Shared/GetTestProjects.proj \
/p:TestsListOutputPath=${{ github.workspace }}/artifacts/TestsForGithubActions.list \
/p:ContinuousIntegrationBuild=true && \
echo "tests_matrix=$(jq -cR '{shortname: [inputs]}' < ${{ github.workspace }}/artifacts/TestsForGithubActions.list)" >> $GITHUB_OUTPUT
$filePath = "${{ github.workspace }}/artifacts/TestsForGithubActions.list"
$lines = Get-Content $filePath
$jsonObject = @{
"shortname" = $lines | Sort-Object
}
$jsonString = ConvertTo-Json $jsonObject -Compress
"tests_matrix=$jsonString"
"tests_matrix=$jsonString" | Out-File -FilePath $env:GITHUB_OUTPUT
_:
test:
uses: ./.github/workflows/run-tests.yml
needs: setup_for_tests
strategy:
Expand All @@ -45,7 +65,7 @@ jobs:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Final Results
needs: [_]
needs: [test]
steps:
# get all the test-job-result* artifacts into a single directory
- uses: actions/download-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Cli.Tests/Hosting/CliOrphanDetectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading.Channels;
using Aspire.Components.Common.Tests;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Cli;
using Aspire.Hosting.Utils;
Expand Down Expand Up @@ -93,6 +94,7 @@ public async Task CliOrphanDetectorAfterTheProcessWasRunningForAWhileThenStops()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7920", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task AppHostExitsWhenCliProcessPidDies()
{
using var fakeCliProcess = RemoteExecutor.Invoke(
Expand Down
6 changes: 5 additions & 1 deletion tests/Aspire.Components.Common.Tests/PlatformDetection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ public static class PlatformDetection
{
public static bool IsRunningOnBuildMachine => Environment.GetEnvironmentVariable("BUILD_BUILDID") is not null;
public static bool IsRunningOnHelix => Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT") is not null;
public static bool IsRunningOnCI => IsRunningOnBuildMachine || IsRunningOnHelix;
public static bool IsRunningOnGithubActions => Environment.GetEnvironmentVariable("GITHUB_JOB") is not null;
public static bool IsRunningOnCI => IsRunningOnBuildMachine || IsRunningOnHelix || IsRunningOnGithubActions;

public static bool IsWindows => OperatingSystem.IsWindows();
public static bool IsLinux => OperatingSystem.IsLinux();
}
1 change: 1 addition & 0 deletions tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(TestsSharedDir)Telemetry\*.cs" LinkBase="shared/Telemetry" />
<Compile Include="$(TestsSharedDir)DashboardModel\*.cs" LinkBase="shared/DashboardModel" />
<Content Include="$(TestsSharedDir)TestCertificates\*.pfx" LinkBase="shared/TestCertificates" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="$(RepoRoot)tests\Aspire.Components.Common.Tests\PlatformDetection.cs" LinkBase="PlatformDetection.cs" />

<Content Include="..\..\src\Aspire.Dashboard\wwwroot\**\*.*" LinkBase="wwwroot" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Components.Common.Tests;
using Aspire.Dashboard.Configuration;
using Aspire.Dashboard.Tests.Integration.Playwright.Infrastructure;
using Aspire.Hosting;
Expand Down Expand Up @@ -29,6 +30,7 @@ public BrowserTokenAuthenticationTests(BrowserTokenDashboardServerFixture dashbo
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7921", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task BrowserToken_LoginPage_Success_RedirectToResources()
{
// Arrange
Expand Down
1 change: 1 addition & 0 deletions tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public async Task GetHttpClientBeforeStart(bool genericEntryPoint)
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7930", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task ArgsPropagateToAppHostConfiguration(bool genericEntryPoint, bool directArgs)
{
string[] args = directArgs ? ["APP_HOST_ARG=42"] : [];
Expand Down
4 changes: 4 additions & 0 deletions tests/Aspire.Hosting.Tests/SlimTestProgramTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Components.Common.Tests;
using Aspire.Hosting.Testing.Tests;
using Microsoft.AspNetCore.InternalTesting;
using Xunit;
Expand All @@ -18,6 +19,7 @@ public SlimTestProgramTests(SlimTestProgramFixture slimTestProgramFixture)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7923", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task TestProjectStartsAndStopsCleanly()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand All @@ -42,6 +44,7 @@ private static async Task EnsureServicesAreRunning(TestProgram testProgram, Canc
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7923", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatch()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand All @@ -60,6 +63,7 @@ public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatc
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/7923", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningOnGithubActions), nameof(PlatformDetection.IsWindows))]
public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatchForReplicatedServices()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<!-- no docker support on helix/windows yet -->
<RunTestsOnHelix Condition="'$(OS)' != 'Windows_NT'">true</RunTestsOnHelix>
<!-- no docker support on github-actions/windows yet -->
<RunTestsOnGithubActions Condition="'$(OS)' == 'Windows_NT'">false</RunTestsOnGithubActions>
<SkipTests Condition="'$(OS)' == 'Windows_NT'">true</SkipTests>

<DeployOutsideOfRepoSupportFilesRelativeDir>staging-archive\</DeployOutsideOfRepoSupportFilesRelativeDir>
Expand Down

0 comments on commit 0ae0f0b

Please sign in to comment.