Skip to content

Commit 0cf003d

Browse files
authored
CSHARP-4241: Smoke tests (#865)
1 parent 9ad5dd6 commit 0cf003d

File tree

11 files changed

+575
-12
lines changed

11 files changed

+575
-12
lines changed

CSharpDriver.sln

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
4848
MongoDBTest.ruleset = MongoDBTest.ruleset
4949
EndProjectSection
5050
EndProject
51-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkippableTests", "tests\SkippableTests\SkippableTests.csproj", "{D198833A-6AC3-4327-8B02-5095455192D0}"
51+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkippableTests", "tests\SkippableTests\SkippableTests.csproj", "{D198833A-6AC3-4327-8B02-5095455192D0}"
5252
EndProject
53-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.TestConsoleApplication", "tests\MongoDB.Driver.TestConsoleApplication\MongoDB.Driver.TestConsoleApplication.csproj", "{2E5780D2-29A5-483C-9CA2-844F45A66D0C}"
53+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Driver.TestConsoleApplication", "tests\MongoDB.Driver.TestConsoleApplication\MongoDB.Driver.TestConsoleApplication.csproj", "{2E5780D2-29A5-483C-9CA2-844F45A66D0C}"
5454
EndProject
55-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AstrolabeWorkloadExecutor", "tests\AstrolabeWorkloadExecutor\AstrolabeWorkloadExecutor.csproj", "{B90F025F-89D3-436A-AD78-6AA304A6E240}"
55+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AstrolabeWorkloadExecutor", "tests\AstrolabeWorkloadExecutor\AstrolabeWorkloadExecutor.csproj", "{B90F025F-89D3-436A-AD78-6AA304A6E240}"
56+
EndProject
57+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.SmokeTests.Sdk", "tests\SmokeTests\MongoDB.Driver.SmokeTests.Sdk\MongoDB.Driver.SmokeTests.Sdk.csproj", "{B711A69F-A337-452C-95E1-A6B15C727CBA}"
58+
EndProject
59+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SmokeTests", "SmokeTests", "{F64BF86A-1EF1-4596-84A6-6B4AB766CD77}"
5660
EndProject
5761
Global
5862
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -136,6 +140,10 @@ Global
136140
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Debug|Any CPU.Build.0 = Debug|Any CPU
137141
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Release|Any CPU.ActiveCfg = Release|Any CPU
138142
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Release|Any CPU.Build.0 = Release|Any CPU
143+
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
144+
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
145+
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
146+
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Release|Any CPU.Build.0 = Release|Any CPU
139147
EndGlobalSection
140148
GlobalSection(SolutionProperties) = preSolution
141149
HideSolutionNode = FALSE
@@ -160,6 +168,8 @@ Global
160168
{D198833A-6AC3-4327-8B02-5095455192D0} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
161169
{2E5780D2-29A5-483C-9CA2-844F45A66D0C} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
162170
{B90F025F-89D3-436A-AD78-6AA304A6E240} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
171+
{B711A69F-A337-452C-95E1-A6B15C727CBA} = {F64BF86A-1EF1-4596-84A6-6B4AB766CD77}
172+
{F64BF86A-1EF1-4596-84A6-6B4AB766CD77} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
163173
EndGlobalSection
164174
GlobalSection(ExtensibilityGlobals) = postSolution
165175
SolutionGuid = {24BEC44B-92B0-43AA-9B15-163459D0C098}

build.cake

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ Task("Package")
561561

562562
Task("PackageNugetPackages")
563563
.IsDependentOn("Build")
564-
.Does(() =>
564+
.Does<BuildConfig>((buildConfig) =>
565565
{
566566
EnsureDirectoryExists(artifactsPackagesDirectory);
567567
CleanDirectory(artifactsPackagesDirectory);
@@ -587,7 +587,7 @@ Task("PackageNugetPackages")
587587
MSBuildSettings = new DotNetMSBuildSettings()
588588
// configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.snupkg
589589
.SetContinuousIntegrationBuild(continuousIntegrationBuild: true)
590-
.WithProperty("PackageVersion", gitVersion.LegacySemVer)
590+
.WithProperty("PackageVersion", buildConfig.PackageVersion)
591591
};
592592
DotNetPack(projectPath, settings);
593593
}
@@ -654,6 +654,49 @@ Task("TestsPackagingProjectReference")
654654
);
655655
});
656656

657+
Task("SmokeTests")
658+
.IsDependentOn("PackageNugetPackages")
659+
.DoesForEach(
660+
GetFiles("./**/SmokeTests/**/*.SmokeTests*.csproj"),
661+
action: (BuildConfig buildConfig, Path testProject) =>
662+
{
663+
var environmentVariables = new Dictionary<string, string>
664+
{
665+
{ "SmokeTestsPackageSha", gitVersion.Sha }
666+
};
667+
668+
var settings = new DotNetTestSettings
669+
{
670+
NoBuild = false,
671+
NoRestore = false,
672+
Configuration = configuration,
673+
ArgumentCustomization = args => args.Append($"-- RunConfiguration.TargetPlatform={buildConfig.TargetPlatform}"),
674+
Framework = buildConfig.Framework,
675+
EnvironmentVariables = environmentVariables,
676+
Loggers = CreateLoggers()
677+
};
678+
679+
var toolSettings = new DotNetToolSettings { EnvironmentVariables = environmentVariables };
680+
681+
Information($"Updating MongoDB package: {buildConfig.PackageVersion} sha: {gitVersion.Sha}");
682+
683+
DotNetTool(
684+
testProject.FullPath,
685+
"add package MongoDB.Driver",
686+
$"--version [{buildConfig.PackageVersion}]",
687+
toolSettings);
688+
689+
DotNetTest(
690+
testProject.FullPath,
691+
settings);
692+
});
693+
694+
Task("SmokeTestsNet472").IsDependentOn("SmokeTests");
695+
Task("SmokeTestsNetCoreApp21").IsDependentOn("SmokeTests");
696+
Task("SmokeTestsNetCoreApp31").IsDependentOn("SmokeTests");
697+
Task("SmokeTestsNet50").IsDependentOn("SmokeTests");
698+
Task("SmokeTestsNet60").IsDependentOn("SmokeTests");
699+
657700
Task("TestsPackaging")
658701
.IsDependentOn("TestsPackagingProjectReference")
659702
.IsDependentOn("Package")
@@ -866,16 +909,20 @@ Setup<BuildConfig>(
866909
// in a different directory with a x64 dotnet host process. This would further complicate our testing for little additional gain.
867910
var framework = targetPlatform == "arm64" ? "net6.0" : lowerTarget switch
868911
{
869-
string s when s.StartsWith("test") && s.EndsWith("net472") => "net472",
870-
string s when s.StartsWith("test") && s.EndsWith("netstandard20") => "netcoreapp2.1",
871-
string s when s.StartsWith("test") && s.EndsWith("netstandard21") => "netcoreapp3.1",
872-
string s when s.StartsWith("test") && s.EndsWith("net60") => "net6.0",
912+
string s when s.EndsWith("net472") => "net472",
913+
string s when s.EndsWith("netstandard20") || s.EndsWith("netcoreapp21") => "netcoreapp2.1",
914+
string s when s.EndsWith("netstandard21") || s.EndsWith("netcoreapp31") => "netcoreapp3.1",
915+
string s when s.EndsWith("net472") => "net472",
916+
string s when s.EndsWith("net50") => "net5.0",
917+
string s when s.EndsWith("net60") => "net6.0",
873918
_ => null
874919
};
875920

876921
var isReleaseMode = lowerTarget.StartsWith("package") || lowerTarget == "release";
877-
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, IsReleaseMode: {isReleaseMode}");
878-
return new BuildConfig(isReleaseMode, framework, targetPlatform);
922+
var packageVersion = lowerTarget.StartsWith("smoketests") ? gitVersion.FullSemVer.Replace('+', '-') : gitVersion.LegacySemVer;
923+
924+
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, IsReleaseMode: {isReleaseMode}, PackageVersion: {packageVersion}");
925+
return new BuildConfig(isReleaseMode, framework, targetPlatform, packageVersion);
879926
});
880927

881928
RunTarget(target);
@@ -884,13 +931,15 @@ public class BuildConfig
884931
{
885932
public bool IsReleaseMode { get; }
886933
public string Framework { get; }
934+
public string PackageVersion { get; }
887935
public string TargetPlatform { get; }
888936

889-
public BuildConfig(bool isReleaseMode, string framework, string targetPlatform)
937+
public BuildConfig(bool isReleaseMode, string framework, string targetPlatform, string packageVersion)
890938
{
891939
IsReleaseMode = isReleaseMode;
892940
Framework = framework;
893941
TargetPlatform = targetPlatform;
942+
PackageVersion = packageVersion;
894943
}
895944
}
896945

build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
101101
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
102102
& bash $ScriptPath --install-dir "$InstallPath" --channel 2.1 --no-path
103103
& bash $ScriptPath --install-dir "$InstallPath" --channel 3.1 --no-path
104+
& bash $ScriptPath --install-dir "$InstallPath" --channel 5.0 --no-path
104105
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
105106

106107
Remove-PathVariable "$InstallPath"
@@ -111,6 +112,7 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
111112
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
112113
& $ScriptPath -Channel 2.1 -InstallDir $InstallPath;
113114
& $ScriptPath -Channel 3.1 -InstallDir $InstallPath;
115+
& $ScriptPath -Channel 5.0 -InstallDir $InstallPath;
114116
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
115117

116118
Remove-PathVariable "$InstallPath"

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
4646
# | arm64 | x64 | x64 | arm64 |
4747
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 2.1 --architecture x64 --install-dir .dotnet --no-path
4848
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 3.1 --architecture x64 --install-dir .dotnet --no-path
49+
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 5.0 --architecture x64 --install-dir .dotnet --no-path
4950
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
5051
export PATH="$SCRIPT_DIR/.dotnet":$PATH
5152
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"

evergreen/evergreen.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,27 @@ functions:
682682
SSL=${SSL} \
683683
evergreen/run-serverless-tests.sh
684684
685+
run-smoke-tests:
686+
- command: shell.exec
687+
type: test
688+
params:
689+
working_dir: mongo-csharp-driver
690+
script: |
691+
set +x
692+
${PREPARE_SHELL}
693+
OS=${OS} \
694+
AUTH=${AUTH} \
695+
SSL=${SSL} \
696+
MONGODB_URI="${MONGODB_URI}" \
697+
TOPOLOGY=${TOPOLOGY} \
698+
OS=${OS} \
699+
COMPRESSOR=${COMPRESSOR} \
700+
CLIENT_PEM=${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem \
701+
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
702+
TARGET="SmokeTests" \
703+
FRAMEWORK=${FRAMEWORK} \
704+
evergreen/run-tests.sh
705+
685706
create-serverless-instance:
686707
- command: shell.exec
687708
params:
@@ -1210,6 +1231,41 @@ tasks:
12101231
OCSP_ALGORITHM: "rsa"
12111232
OCSP_TLS_SHOULD_SUCCEED: "false"
12121233

1234+
- name: test-smoke-tests-net472
1235+
commands:
1236+
- func: bootstrap-mongo-orchestration
1237+
- func: run-smoke-tests
1238+
vars:
1239+
FRAMEWORK: net472
1240+
1241+
- name: test-smoke-tests-netcoreapp21
1242+
commands:
1243+
- func: bootstrap-mongo-orchestration
1244+
- func: run-smoke-tests
1245+
vars:
1246+
FRAMEWORK: netcoreapp21
1247+
1248+
- name: test-smoke-tests-netcoreapp31
1249+
commands:
1250+
- func: bootstrap-mongo-orchestration
1251+
- func: run-smoke-tests
1252+
vars:
1253+
FRAMEWORK: netcoreapp31
1254+
1255+
- name: test-smoke-tests-net50
1256+
commands:
1257+
- func: bootstrap-mongo-orchestration
1258+
- func: run-smoke-tests
1259+
vars:
1260+
FRAMEWORK: net50
1261+
1262+
- name: test-smoke-tests-net60
1263+
commands:
1264+
- func: bootstrap-mongo-orchestration
1265+
- func: run-smoke-tests
1266+
vars:
1267+
FRAMEWORK: net60
1268+
12131269
# ECDSA tests
12141270
# Disabled until https://jira.mongodb.org/browse/SPEC-1589 is resolved
12151271
# - name: test-ocsp-ecdsa-valid-cert-server-staples-ca-responder
@@ -1820,3 +1876,35 @@ buildvariants:
18201876
batchtime: 20160 # 14 days
18211877
tasks:
18221878
- name: testgcpkms-task-group
1879+
- name: test-csfle-with-mongocryptd-netstandard21
1880+
1881+
- matrix_name: "smoke-tests-windows"
1882+
matrix_spec: { os: "windows-64", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
1883+
display_name: "smoke-tests ${version} ${os}"
1884+
batchtime: 1440 # 1 day
1885+
tasks:
1886+
- name: test-smoke-tests-net472
1887+
- name: test-smoke-tests-netcoreapp21
1888+
- name: test-smoke-tests-netcoreapp31
1889+
- name: test-smoke-tests-net50
1890+
- name: test-smoke-tests-net60
1891+
1892+
- matrix_name: "smoke-tests-linux"
1893+
matrix_spec: { os: "ubuntu-1804", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
1894+
display_name: "smoke-tests ${version} ${os}"
1895+
batchtime: 1440 # 1 day
1896+
tasks:
1897+
- name: test-smoke-tests-netcoreapp21
1898+
- name: test-smoke-tests-netcoreapp31
1899+
- name: test-smoke-tests-net50
1900+
- name: test-smoke-tests-net60
1901+
1902+
- matrix_name: "smoke-tests-macOS"
1903+
matrix_spec: { os: "macos-1100", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
1904+
display_name: "smoke-tests ${version} ${os}"
1905+
batchtime: 1440 # 1 day
1906+
tasks:
1907+
- name: test-smoke-tests-netcoreapp21
1908+
- name: test-smoke-tests-netcoreapp31
1909+
- name: test-smoke-tests-net50
1910+
- name: test-smoke-tests-net60
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Diagnostics;
18+
using FluentAssertions;
19+
20+
namespace MongoDB.Driver.SmokeTests.Sdk
21+
{
22+
internal static class InfrastructureUtilities
23+
{
24+
public static void ValidateMongoDBPackageVersion()
25+
{
26+
var packageShaExpected = Environment.GetEnvironmentVariable("SmokeTestsPackageSha");
27+
28+
if (!string.IsNullOrEmpty(packageShaExpected))
29+
{
30+
var fileVersionInfo = FileVersionInfo.GetVersionInfo(typeof(MongoClient).Assembly.Location);
31+
32+
fileVersionInfo.ProductVersion.Contains(packageShaExpected)
33+
.Should().BeTrue("Expected package sha {0} in {1}", packageShaExpected, fileVersionInfo.ProductVersion);
34+
}
35+
}
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using Microsoft.Extensions.Logging;
17+
18+
namespace MongoDB.Driver.SmokeTests.Sdk
19+
{
20+
internal struct LogEntry
21+
{
22+
public LogEntry(LogLevel logLevel, string category, string message)
23+
{
24+
LogLevel = logLevel;
25+
Category = category;
26+
Message = message;
27+
}
28+
29+
public LogLevel LogLevel { get; }
30+
public string Category { get; }
31+
public string Message { get; }
32+
33+
public override string ToString() => $"{LogLevel}_{Category}_{Message}";
34+
}
35+
}

0 commit comments

Comments
 (0)