Skip to content

CSHARP-5592: Separate unit tests into dedicated variants #1695

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

Merged
merged 4 commits into from
May 23, 2025
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: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Task("Test")
Console.WriteLine($"MONGO_X509_CLIENT_CERTIFICATE_PASSWORD={mongoX509ClientCertificatePassword}");
}

RunTests(buildConfig, testProject);
RunTests(buildConfig, testProject, filter: "Category=\"Integration\"");
})
.DeferOnError();

Expand Down
86 changes: 84 additions & 2 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ functions:
install-dotnet:
- command: shell.exec
params:
include_expansions_in_env:
- "OS"
- "DOTNET_SDK_VERSION"
- "FRAMEWORK"
script: |
${PREPARE_SHELL}
OS=${OS} DOTNET_SDK_VERSION=${DOTNET_SDK_VERSION} bash ${PROJECT_DIRECTORY}/evergreen/install-dotnet.sh
bash ${PROJECT_DIRECTORY}/evergreen/install-dotnet.sh

prepare-resources:
- command: shell.exec
Expand Down Expand Up @@ -352,6 +356,18 @@ functions:
cd ${DRIVERS_TOOLS}/.evergreen
DRIVERS_TOOLS=${DRIVERS_TOOLS} MONGODB_URI=${MONGODB_URI} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop

run-unit-tests:
- command: shell.exec
type: test
params:
working_dir: mongo-csharp-driver
shell: "bash"
include_expansions_in_env:
- "FRAMEWORK"
script: |
${PREPARE_SHELL}
bash evergreen/run-unit-tests.sh

run-tests:
- command: shell.exec
type: test
Expand Down Expand Up @@ -508,7 +524,7 @@ functions:

echo "Response Body: $response_body"
echo "HTTP Status: $http_status"

assume-ec2-role:
- command: ec2.assume_role
params:
Expand Down Expand Up @@ -1031,6 +1047,36 @@ post:
- func: cleanup

tasks:
- name: unit-tests-net472
commands:
- command: expansions.update
params:
updates:
- key: 'FRAMEWORK'
value: 'net472'
- func: install-dotnet
- func: run-unit-tests

- name: unit-tests-netstandard21
commands:
- command: expansions.update
params:
updates:
- key: 'FRAMEWORK'
value: 'netstandard2.1'
- func: install-dotnet
- func: run-unit-tests

- name: unit-tests-net60
commands:
- command: expansions.update
params:
updates:
- key: 'FRAMEWORK'
value: 'net6.0'
- func: install-dotnet
- func: run-unit-tests

- name: test-net472
commands:
- func: setup-csfle-secrets
Expand Down Expand Up @@ -2179,6 +2225,42 @@ task_groups:
- validate-apicompat

buildvariants:
- name: unit-tests-windows
display_name: Unit Tests on Windows
run_on: windows-64-vs2017-test
expansions:
OS: "windows-64"
tasks:
- name: unit-tests-net472
- name: unit-tests-netstandard21
- name: unit-tests-net60

- name: unit-tests-ubuntu
display_name: Unit Tests on Ubuntu
run_on: ubuntu2004-small
expansions:
OS: "ubuntu-2004"
tasks:
- name: unit-tests-netstandard21
- name: unit-tests-net60

- name: unit-tests-macos
display_name: Unit Tests on MacOs
run_on: macos-14
expansions:
OS: "macos-14"
tasks:
- name: unit-tests-netstandard21
- name: unit-tests-net60

- name: unit-tests-macos-arm
display_name: Unit Tests on MacOs Arm
run_on: macos-14-arm64
expansions:
OS: "macos-14-arm64"
tasks:
- name: unit-tests-net60

- matrix_name: stable-api-tests
matrix_spec: { version: ["5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: "standalone", auth: "auth", ssl: "nossl", os: "windows-64" }
display_name: "Stable API ${version} ${topology} ${auth} ${ssl} ${os}"
Expand Down
22 changes: 20 additions & 2 deletions evergreen/install-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@ set -o errexit # Exit the script with error if any of the commands fail
DOTNET_SDK_PATH="${DOTNET_SDK_PATH:-./.dotnet}"
DOTNET_SDK_VERSION="${DOTNET_SDK_VERSION:-8.0}"

echo "runtime: $FRAMEWORK"

if [ -n "$FRAMEWORK" ]; then
if [ "$FRAMEWORK" = "net6.0" ]; then
RUNTIME_VERSION="6.0"
elif [ "$FRAMEWORK" = "netstandard2.1" ]; then
RUNTIME_VERSION="3.1"
fi
fi

if [[ $OS =~ [Ww]indows.* ]]; then
echo "Downloading Windows .NET SDK installer into $DOTNET_SDK_PATH folder..."
curl -Lfo ./dotnet-install.ps1 https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.ps1
echo "Installing .NET 8.0 SDK..."
echo "Installing .NET ${DOTNET_SDK_VERSION} SDK..."
powershell.exe ./dotnet-install.ps1 -Channel "$DOTNET_SDK_VERSION" -InstallDir "$DOTNET_SDK_PATH" -NoPath
if [ -n "$RUNTIME_VERSION" ]; then
echo "Installing .NET ${RUNTIME_VERSION} runtime..."
powershell.exe ./dotnet-install.ps1 -Channel "$RUNTIME_VERSION" -Runtime dotnet -InstallDir "$DOTNET_SDK_PATH" -NoPath
fi
else
echo "Downloading .NET SDK installer into $DOTNET_SDK_PATH folder..."
curl -Lfo ./dotnet-install.sh https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh
echo "Installing .NET 8.0 SDK..."
echo "Installing .NET ${DOTNET_SDK_VERSION} SDK..."
bash ./dotnet-install.sh --channel "$DOTNET_SDK_VERSION" --install-dir "$DOTNET_SDK_PATH" --no-path
if [ -n "$RUNTIME_VERSION" ]; then
echo "Installing .NET ${RUNTIME_VERSION} runtime..."
bash ./dotnet-install.sh --channel "$RUNTIME_VERSION" --runtime dotnet --install-dir "$DOTNET_SDK_PATH" --no-path
fi
fi
11 changes: 11 additions & 0 deletions evergreen/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -o errexit # Exit the script with error if any of the commands fail

FRAMEWORK=${FRAMEWORK:-net6.0}

if [ "$FRAMEWORK" = "netstandard2.1" ]; then
FRAMEWORK="netcoreapp3.1"
fi

dotnet build
dotnet test --no-build --filter "Category!=Integration" -f "$FRAMEWORK" --results-directory ./build/test-results --logger "junit;verbosity=detailed;LogFileName=TEST-{assembly}.xml;FailureBodyFormat=Verbose" --logger "console;verbosity=detailed"
1 change: 1 addition & 0 deletions tests/AtlasConnectivity.Tests/ConnectivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace AtlasConnectivity.Tests
{
[Trait("Category", "Integration")]
public class ConnectivityTests : LoggableTestClass
{
// public constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Import Project="..\BuildProps\Tests.Build.props" />

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<CodeAnalysisRuleSet>..\..\MongoDBLegacyTest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace MongoDB.Driver.Examples.Aws
/// 4. To work with EC2 container credentials from EC2 instance metadata make sure a test is launched on EC2 env and AWS_CONTAINER_CREDENTIALS_* is not set
/// 5. To work with Aws WebIdentityToken make sure that AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN and AWS_ROLE_SESSION_NAME are configured
/// </summary>
[Trait("Category", "Integration")]
public class AwsAuthenticationExamples
{
private static readonly string __connectionStringHosts = "<host_address>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class CausalConsistencyExamples
{
[Fact]
Expand Down
1 change: 1 addition & 0 deletions tests/MongoDB.Driver.Examples/ChangeStreamExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class ChangeStreamExamples
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class ClientEncryptionExamples
{
private const string LocalMasterKey = "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class ClientSideEncryption2Examples
{
private const string LocalMasterKey = "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk";
Expand Down
31 changes: 16 additions & 15 deletions tests/MongoDB.Driver.Examples/DocumentationExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class DocumentationExamples
{
private readonly IMongoClient client;
Expand All @@ -41,7 +42,7 @@ public DocumentationExamples()
[Fact]
public void Example_1()
{
// db.inventory.insertOne( { item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } } )
// db.inventory.insertOne( { item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } } )

// Start Example 1
var document = new BsonDocument
Expand Down Expand Up @@ -76,10 +77,10 @@ public void Example_2()
[Fact]
public void Example_3()
{
// db.inventory.insertMany([
// db.inventory.insertMany([
// { item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom: "cm" } },
// { item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } },
// { item: "mousepad", qty: 25, tags: ["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } } ])
// { item: "mousepad", qty: 25, tags: ["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } } ])

// Start Example 3
var documents = new BsonDocument[]
Expand Down Expand Up @@ -125,7 +126,7 @@ public void Example_6()
// { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" },
// { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
// { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
// { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" } ])
// { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" } ])

// Start Example 6
var documents = new BsonDocument[]
Expand Down Expand Up @@ -265,7 +266,7 @@ public void Example_13()
[Fact]
public void Example_14()
{
// db.inventory.insertMany( [
// db.inventory.insertMany( [
// { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
// { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" },
// { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
Expand Down Expand Up @@ -392,7 +393,7 @@ public void Example_19()
[Fact]
public void Example_20()
{
// db.inventory.insertMany([
// db.inventory.insertMany([
// { item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
// { item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ] },
// { item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ] },
Expand Down Expand Up @@ -559,7 +560,7 @@ public void Example_28()
[Fact]
public void Example_29()
{
// db.inventory.insertMany( [
// db.inventory.insertMany( [
// { item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] },
// { item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },
// { item: "paper", instock: [ { warehouse: "A", qty: 60 }, { warehouse: "B", qty: 15 } ] },
Expand Down Expand Up @@ -795,7 +796,7 @@ public void Example_41()
[Fact]
public void Example_42()
{
// db.inventory.insertMany( [
// db.inventory.insertMany( [
// { item: "journal", status: "A", size: { h: 14, w: 21, uom: "cm" }, instock: [ { warehouse: "A", qty: 5 } ] },
// { item: "notebook", status: "A", size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "C", qty: 5 } ] },
// { item: "paper", status: "D", size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "A", qty: 60 } ] },
Expand Down Expand Up @@ -992,7 +993,7 @@ public void Example_50()
[Fact]
public void Example_51()
{
// db.inventory.insertMany( [
// db.inventory.insertMany( [
// { item: "canvas", qty: 100, size: { h: 28, w: 35.5, uom: "cm" }, status: "A" },
// { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
// { item: "mat", qty: 85, size: { h: 27.9, w: 35.5, uom: "cm" }, status: "A" },
Expand All @@ -1002,7 +1003,7 @@ public void Example_51()
// { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
// { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
// { item: "sketchbook", qty: 80, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
// { item: "sketch pad", qty: 95, size: { h: 22.85, w: 30.5, uom: "cm" }, status: "A" } ]);
// { item: "sketch pad", qty: 95, size: { h: 22.85, w: 30.5, uom: "cm" }, status: "A" } ]);

// Start Example 51
var documents = new[]
Expand Down Expand Up @@ -1149,12 +1150,12 @@ public void Example_54()
[Fact]
public void Example_55()
{
// db.inventory.insertMany( [
// db.inventory.insertMany( [
// { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
// { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
// { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
// { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
// { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }, ]);
// { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }, ]);

// Start Example 55
var documents = new[]
Expand Down Expand Up @@ -1252,7 +1253,7 @@ public void Aggregation_Example_1()
{
RequireServer.Check();

//db.sales.aggregate([
//db.sales.aggregate([
// { $match : { "items.fruit":"banana" } },
// { $sort : { "date" : 1 } }
//])
Expand Down Expand Up @@ -1347,7 +1348,7 @@ public void Aggregation_Example_3()
// }
//},
//{
// $project: { day: "$_id.day", revenue: 1, items_sold: 1,
// $project: { day: "$_id.day", revenue: 1, items_sold: 1,
// discount: { $cond: { if : { $lte: ["$revenue", 250] }, then: 25, else : 0 }}
// }
//}])
Expand Down Expand Up @@ -1421,7 +1422,7 @@ public void Aggregation_Example_4()
// $project : {
// "_id" : 0,
// "name" : 1,
// airlines : {
// airlines : {
// $filter : {
// input : "$airlines",
// as : "airline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class ExplicitEncryptionExamples
{
private const string LocalMasterKey = "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk";
Expand Down
2 changes: 2 additions & 0 deletions tests/MongoDB.Driver.Examples/PrimerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
using System.IO;
using System.Reflection;
using MongoDB.Bson;
using Xunit;

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public abstract class PrimerTestFixture
{
protected static IMongoClient __client;
Expand Down
1 change: 1 addition & 0 deletions tests/MongoDB.Driver.Examples/StableApiExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace MongoDB.Driver.Examples
{
[Trait("Category", "Integration")]
public class StableApiExamples
{
[Fact]
Expand Down
Loading