Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Run each test project on a separate runner #1295

Merged
merged 1 commit into from
Nov 10, 2024
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
2 changes: 2 additions & 0 deletions .cake-scripts/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class BuildParameters
public string PullRequestId { get; private set; }
public string Version { get; private set; }
public string TestFilter { get; private set; }
public string TestProject { get; private set; }
public bool IsLocalBuild { get; private set; }
public bool IsReleaseBuild { get; private set; }
public bool IsPullRequest { get; private set; }
Expand Down Expand Up @@ -49,6 +50,7 @@ internal sealed class BuildParameters
PullRequestId = buildInformation.PullRequestId,
Version = buildInformation.Version,
TestFilter = context.Argument<string>("test-filter", null),
TestProject = context.Argument<string>("test-project", null),
IsLocalBuild = buildInformation.IsLocalBuild,
IsReleaseBuild = !buildInformation.IsLocalBuild && buildInformation.IsReleaseBuild,
IsPullRequest = buildInformation.IsPullRequest,
Expand Down
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
2 changes: 1 addition & 1 deletion .cake-scripts/version.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#addin nuget:?package=Cake.Git&version=3.0.0
#addin nuget:?package=Cake.Git&version=4.0.0

internal sealed class BuildInformation
{
Expand Down
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "3.2.0",
"version": "4.2.0",
"commands": [
"dotnet-cake"
]
Expand Down
102 changes: 63 additions & 39 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,61 @@ 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 }}
test-projects: [
{ name: "Testcontainers", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Platform.Linux", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Platform.Windows", runs-on: "windows-2022" },
{ name: "Testcontainers.Databases", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.ResourceReaper", runs-on: "ubuntu-22.04" },
{ 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.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.test-projects.runs-on }}

steps:
- name: Checkout Repository
Expand All @@ -42,27 +90,9 @@ jobs:
- name: Cache NuGet Packages
uses: actions/cache@v4
with:
key: ${{ matrix.os }}-nuget-${{ hashFiles('Directory.Packages.props') }}
key: ${{ matrix.test-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/free-disk-space@v1.3.1
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,28 +106,28 @@ 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-project=${{ matrix.test-projects.name }}

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

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

needs: build
needs: ci

environment: production

runs-on: ubuntu-22.04

permissions:
contents: write
pull-requests: read

runs-on: ubuntu-22.04

env:
CODE_SIGNING_CERTIFICATE_BASE64: ${{ secrets.CODE_SIGNING_CERTIFICATE_BASE64 }}
CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CERTIFICATE_PASSWORD }}
Expand All @@ -116,16 +146,10 @@ jobs:
lfs: true
fetch-depth: 0

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

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

- name: Fix Absolute Code Coverage Paths
Expand All @@ -142,7 +166,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 Down
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/test-reporter@v1.9.1
with:
artifact: ${{ matrix.os }}
name: report (${{ matrix.os }})
artifact: Testcontainers*
name: Test Report
path: '*.trx'
reporter: dotnet-trx
31 changes: 27 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#tool nuget:?package=dotnet-sonarscanner&version=9.0.0
#tool nuget:?package=dotnet-sonarscanner&version=9.0.1

#addin nuget:?package=Cake.Sonar&version=1.1.32
#addin nuget:?package=Cake.Sonar&version=1.1.33

#addin nuget:?package=Cake.Git&version=3.0.0
#addin nuget:?package=Cake.Git&version=4.0.0

#load ".cake-scripts/parameters.cake"

Expand Down Expand Up @@ -71,6 +71,26 @@ Task("Build")
});
});

Task("Test")
.Does(() =>
{
var testProject = param.Projects.OnlyTests
.Select(testProject => testProject.Path.FullPath)
.Single(testProject => testProject.EndsWith(param.TestProject + ".Tests.csproj"));

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 Expand Up @@ -111,7 +131,10 @@ Task("Sonar-Begin")
PullRequestBranch = param.SourceBranch,
PullRequestBase = param.TargetBranch,
OpenCoverReportsPath = $"{MakeAbsolute(param.Paths.Directories.TestResultsDirectoryPath)}/**/*.opencover.xml",
VsTestReportsPath = $"{MakeAbsolute(param.Paths.Directories.TestResultsDirectoryPath)}/**/*.trx"
VsTestReportsPath = $"{MakeAbsolute(param.Paths.Directories.TestResultsDirectoryPath)}/**/*.trx",
ArgumentCustomization = args => args
.Append("/d:sonar.scanner.scanAll=\"false\"")
.Append("/d:sonar.scanner.skipJreProvisioning=\"true\"")
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public sealed class HttpFixture : IAsyncLifetime
private readonly IContainer _container = new ContainerBuilder()
.WithImage(CommonImages.Alpine)
.WithEntrypoint("/bin/sh", "-c")
.WithCommand($"while true; do echo \"HTTP/1.1 200 OK\r\n\" | nc -l -p {HttpPort}; done")
.WithCommand($"while true; do echo \"HTTP/1.1 200 OK\r\n\r\n\" | nc -l -p {HttpPort}; done")
.WithPortBinding(HttpPort, true)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class WaitUntilHttpRequestIsSucceededTest : IAsyncLifetime
private readonly IContainer _container = new ContainerBuilder()
.WithImage(CommonImages.Alpine)
.WithEntrypoint("/bin/sh", "-c")
.WithCommand($"while true; do echo \"HTTP/1.1 200 OK\r\n\" | nc -l -p {HttpPort}; done")
.WithCommand($"while true; do echo \"HTTP/1.1 200 OK\r\n\r\n\" | nc -l -p {HttpPort}; done")
.WithPortBinding(HttpPort, true)
.Build();

Expand Down