Skip to content

Commit

Permalink
test: Run test projects parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Nov 9, 2024
1 parent db02434 commit 25a2b84
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .cake-scripts/paths.cake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class BuildPaths

public static BuildPaths Instance(ICakeContext context, string version)
{
var baseDir = (DirectoryPath) context.Directory(".");
var baseDir = (DirectoryPath)context.Directory(".");

var testResultsDir = baseDir.Combine("test-results");
var testCoverageDir = baseDir.Combine("test-coverage");
Expand Down
150 changes: 85 additions & 65 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,57 @@ env:
TZ: CET # https://stackoverflow.com/q/53510011

jobs:
build:
ci:
strategy:
fail-fast: false
max-parallel: 6
matrix:
os: [ ubuntu-22.04, windows-2022 ]

runs-on: ${{ matrix.os }}
projects: [
{ name: "Testcontainers.ActiveMq", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.ArangoDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Azurite", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.BigQuery", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Bigtable", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.ClickHouse", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.CockroachDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Consul", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.CosmosDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Couchbase", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.CouchDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Databases", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.DynamoDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Elasticsearch", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.EventStoreDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.FakeGcsServer", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.FirebirdSql", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Firestore", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.InfluxDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.JanusGraph", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.K3s", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Kafka", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Keycloak", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Kusto", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.LocalStack", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.MariaDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Milvus", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Minio", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.MongoDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.MsSql", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.MySql", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Nats", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Neo4j", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Oracle", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Papercut", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.PostgreSql", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.PubSub", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Pulsar", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.RabbitMq", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.RavenDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Redis", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Redpanda", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.WebDriver", runs-on: "ubuntu-22.04" }
]

runs-on: ${{ matrix.projects.runs-on }}

steps:
- name: Checkout Repository
Expand All @@ -42,27 +86,9 @@ jobs:
- name: Cache NuGet Packages
uses: actions/cache@v4
with:
key: ${{ matrix.os }}-nuget-${{ hashFiles('Directory.Packages.props') }}
key: ${{ matrix.projects.runs-on }}-nuget-${{ hashFiles('Directory.Packages.props') }}
path: ~/.nuget/packages

# Our modules occupy too much disk space. The GitHub-hosted runners ran into the
# error: "no space left on device." The pulled images are not cleaned up between
# the test runs. One obvious approach is splitting the tests and running them on
# multiple runners. However, we need to keep in mind that running too many
# simultaneous builds has an impact on others as well. We observed that scheduled
# Dependabot builds blocked others in the Testcontainers organization.
- name: Free Disk Space
uses: jlumbroso/[email protected]
if: runner.os == 'Linux'
with:
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false

- name: Setup .NET
uses: actions/setup-dotnet@v4

Expand All @@ -76,38 +102,38 @@ jobs:
run: dotnet cake --target=Build

- name: Run Tests
run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }}
run: dotnet cake --target=Test --test-filter=${{ matrix.projects.name }}

- name: Upload Test And Coverage Results
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.os }}
name: ${{ matrix.projects.name }}
path: test-results

publish:
if: ${{ contains(fromJson('["develop", "main"]'), github.ref_name) }}
cd:
# if: ${{ contains(fromJson('["develop", "main"]'), github.ref_name) }}

needs: build
needs: ci

environment: production
# environment: production

# permissions:
# contents: write
# pull-requests: read

runs-on: ubuntu-22.04

permissions:
contents: write
pull-requests: read

env:
CODE_SIGNING_CERTIFICATE_BASE64: ${{ secrets.CODE_SIGNING_CERTIFICATE_BASE64 }}
CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CERTIFICATE_PASSWORD }}
FEED_SOURCE: https://api.nuget.org/v3/index.json
FEED_API_KEY: ${{ secrets.FEED_API_KEY }}
SONARCLOUD_URL: https://sonarcloud.io
SONARCLOUD_ORGANIZATION: testcontainers
SONARCLOUD_KEY: testcontainers_testcontainers-dotnet
SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
PUBLISH_NUGET_PACKAGE: ${{ inputs.publish_nuget_package }}
# env:
# CODE_SIGNING_CERTIFICATE_BASE64: ${{ secrets.CODE_SIGNING_CERTIFICATE_BASE64 }}
# CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CERTIFICATE_PASSWORD }}
# FEED_SOURCE: https://api.nuget.org/v3/index.json
# FEED_API_KEY: ${{ secrets.FEED_API_KEY }}
# SONARCLOUD_URL: https://sonarcloud.io
# SONARCLOUD_ORGANIZATION: testcontainers
# SONARCLOUD_KEY: testcontainers_testcontainers-dotnet
# SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
# PUBLISH_NUGET_PACKAGE: ${{ inputs.publish_nuget_package }}

steps:
- name: Checkout Repository
Expand All @@ -116,16 +142,10 @@ jobs:
lfs: true
fetch-depth: 0

- name: Download Test And Coverage Results (ubuntu-22.04)
- name: Download Test And Coverage Results
uses: actions/download-artifact@v4
with:
name: ubuntu-22.04
path: test-results

- name: Download Test And Coverage Results (windows-2022)
uses: actions/download-artifact@v4
with:
name: windows-2022
pattern: Testcontainers*
path: test-results

- name: Fix Absolute Code Coverage Paths
Expand All @@ -142,7 +162,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21

- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand All @@ -153,21 +173,21 @@ jobs:
- name: Restore NuGet Packages
run: dotnet cake --target=Restore-NuGet-Packages

- name: Run Sonar Analysis
run: dotnet cake --target=Sonar-Begin
# - name: Run Sonar Analysis
# run: dotnet cake --target=Sonar-Begin

- name: Run Build
run: dotnet cake --target=Build

- name: Upload Sonar Results
run: dotnet cake --target=Sonar-End
# - name: Upload Sonar Results
# run: dotnet cake --target=Sonar-End

- name: Publish NuGet Package
run: dotnet cake --target=Publish
# - name: Publish NuGet Package
# run: dotnet cake --target=Publish

# Cake sets the semVer environment variable
- uses: release-drafter/release-drafter@v6
with:
version: ${{ env.semVer }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# # Cake sets the semVer environment variable
# - uses: release-drafter/release-drafter@v6
# with:
# version: ${{ env.semVer }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 4 additions & 9 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,19 @@ on:

jobs:
report:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, windows-2022 ]

runs-on: ${{ matrix.os }}

permissions:
actions: read
checks: write
contents: read

runs-on: ubuntu-22.04

steps:
# https://github.com/dorny/test-reporter/issues/363#issuecomment-2381625959.
- name: Publish Test Report
uses: dorny/[email protected]
with:
artifact: ${{ matrix.os }}
name: report (${{ matrix.os }})
artifact: Testcontainers*
name: Test Report
path: '*.trx'
reporter: dotnet-trx
21 changes: 21 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ Task("Build")
});
});

Task("Test")
.Does(() =>
{
var testProject = param.Projects.OnlyTests
.Select(testProject => testProject.Path.FullPath)
.Single(testProject => testProject.Contains(param.TestFilter));
DotNetTest(testProject, new DotNetTestSettings
{
Configuration = param.Configuration,
Verbosity = param.Verbosity,
NoRestore = true,
NoBuild = true,
Collectors = new[] { "XPlat Code Coverage;Format=opencover" },
ResultsDirectory = param.Paths.Directories.TestResultsDirectoryPath,
ArgumentCustomization = args => args
.AppendSwitchQuoted("--blame-hang-timeout", "5m")
});
});

Task("Tests")
.Does(() =>
{
Expand Down

0 comments on commit 25a2b84

Please sign in to comment.