Skip to content

Commit

Permalink
CSHARP-4241: Smoke tests (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisDog committed Sep 30, 2022
1 parent 9ad5dd6 commit 0cf003d
Show file tree
Hide file tree
Showing 11 changed files with 575 additions and 12 deletions.
16 changes: 13 additions & 3 deletions CSharpDriver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
MongoDBTest.ruleset = MongoDBTest.ruleset
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkippableTests", "tests\SkippableTests\SkippableTests.csproj", "{D198833A-6AC3-4327-8B02-5095455192D0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkippableTests", "tests\SkippableTests\SkippableTests.csproj", "{D198833A-6AC3-4327-8B02-5095455192D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Driver.TestConsoleApplication", "tests\MongoDB.Driver.TestConsoleApplication\MongoDB.Driver.TestConsoleApplication.csproj", "{2E5780D2-29A5-483C-9CA2-844F45A66D0C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Driver.TestConsoleApplication", "tests\MongoDB.Driver.TestConsoleApplication\MongoDB.Driver.TestConsoleApplication.csproj", "{2E5780D2-29A5-483C-9CA2-844F45A66D0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AstrolabeWorkloadExecutor", "tests\AstrolabeWorkloadExecutor\AstrolabeWorkloadExecutor.csproj", "{B90F025F-89D3-436A-AD78-6AA304A6E240}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AstrolabeWorkloadExecutor", "tests\AstrolabeWorkloadExecutor\AstrolabeWorkloadExecutor.csproj", "{B90F025F-89D3-436A-AD78-6AA304A6E240}"
EndProject
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}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SmokeTests", "SmokeTests", "{F64BF86A-1EF1-4596-84A6-6B4AB766CD77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -136,6 +140,10 @@ Global
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B90F025F-89D3-436A-AD78-6AA304A6E240}.Release|Any CPU.Build.0 = Release|Any CPU
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B711A69F-A337-452C-95E1-A6B15C727CBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -160,6 +168,8 @@ Global
{D198833A-6AC3-4327-8B02-5095455192D0} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
{2E5780D2-29A5-483C-9CA2-844F45A66D0C} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
{B90F025F-89D3-436A-AD78-6AA304A6E240} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
{B711A69F-A337-452C-95E1-A6B15C727CBA} = {F64BF86A-1EF1-4596-84A6-6B4AB766CD77}
{F64BF86A-1EF1-4596-84A6-6B4AB766CD77} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {24BEC44B-92B0-43AA-9B15-163459D0C098}
Expand Down
67 changes: 58 additions & 9 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ Task("Package")

Task("PackageNugetPackages")
.IsDependentOn("Build")
.Does(() =>
.Does<BuildConfig>((buildConfig) =>
{
EnsureDirectoryExists(artifactsPackagesDirectory);
CleanDirectory(artifactsPackagesDirectory);
Expand All @@ -587,7 +587,7 @@ Task("PackageNugetPackages")
MSBuildSettings = new DotNetMSBuildSettings()
// configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.snupkg
.SetContinuousIntegrationBuild(continuousIntegrationBuild: true)
.WithProperty("PackageVersion", gitVersion.LegacySemVer)
.WithProperty("PackageVersion", buildConfig.PackageVersion)
};
DotNetPack(projectPath, settings);
}
Expand Down Expand Up @@ -654,6 +654,49 @@ Task("TestsPackagingProjectReference")
);
});

Task("SmokeTests")
.IsDependentOn("PackageNugetPackages")
.DoesForEach(
GetFiles("./**/SmokeTests/**/*.SmokeTests*.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
{
var environmentVariables = new Dictionary<string, string>
{
{ "SmokeTestsPackageSha", gitVersion.Sha }
};
var settings = new DotNetTestSettings
{
NoBuild = false,
NoRestore = false,
Configuration = configuration,
ArgumentCustomization = args => args.Append($"-- RunConfiguration.TargetPlatform={buildConfig.TargetPlatform}"),
Framework = buildConfig.Framework,
EnvironmentVariables = environmentVariables,
Loggers = CreateLoggers()
};
var toolSettings = new DotNetToolSettings { EnvironmentVariables = environmentVariables };
Information($"Updating MongoDB package: {buildConfig.PackageVersion} sha: {gitVersion.Sha}");
DotNetTool(
testProject.FullPath,
"add package MongoDB.Driver",
$"--version [{buildConfig.PackageVersion}]",
toolSettings);
DotNetTest(
testProject.FullPath,
settings);
});

Task("SmokeTestsNet472").IsDependentOn("SmokeTests");
Task("SmokeTestsNetCoreApp21").IsDependentOn("SmokeTests");
Task("SmokeTestsNetCoreApp31").IsDependentOn("SmokeTests");
Task("SmokeTestsNet50").IsDependentOn("SmokeTests");
Task("SmokeTestsNet60").IsDependentOn("SmokeTests");

Task("TestsPackaging")
.IsDependentOn("TestsPackagingProjectReference")
.IsDependentOn("Package")
Expand Down Expand Up @@ -866,16 +909,20 @@ Setup<BuildConfig>(
// in a different directory with a x64 dotnet host process. This would further complicate our testing for little additional gain.
var framework = targetPlatform == "arm64" ? "net6.0" : lowerTarget switch
{
string s when s.StartsWith("test") && s.EndsWith("net472") => "net472",
string s when s.StartsWith("test") && s.EndsWith("netstandard20") => "netcoreapp2.1",
string s when s.StartsWith("test") && s.EndsWith("netstandard21") => "netcoreapp3.1",
string s when s.StartsWith("test") && s.EndsWith("net60") => "net6.0",
string s when s.EndsWith("net472") => "net472",
string s when s.EndsWith("netstandard20") || s.EndsWith("netcoreapp21") => "netcoreapp2.1",
string s when s.EndsWith("netstandard21") || s.EndsWith("netcoreapp31") => "netcoreapp3.1",
string s when s.EndsWith("net472") => "net472",
string s when s.EndsWith("net50") => "net5.0",
string s when s.EndsWith("net60") => "net6.0",
_ => null
};
var isReleaseMode = lowerTarget.StartsWith("package") || lowerTarget == "release";
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, IsReleaseMode: {isReleaseMode}");
return new BuildConfig(isReleaseMode, framework, targetPlatform);
var packageVersion = lowerTarget.StartsWith("smoketests") ? gitVersion.FullSemVer.Replace('+', '-') : gitVersion.LegacySemVer;
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, IsReleaseMode: {isReleaseMode}, PackageVersion: {packageVersion}");
return new BuildConfig(isReleaseMode, framework, targetPlatform, packageVersion);
});

RunTarget(target);
Expand All @@ -884,13 +931,15 @@ public class BuildConfig
{
public bool IsReleaseMode { get; }
public string Framework { get; }
public string PackageVersion { get; }
public string TargetPlatform { get; }

public BuildConfig(bool isReleaseMode, string framework, string targetPlatform)
public BuildConfig(bool isReleaseMode, string framework, string targetPlatform, string packageVersion)
{
IsReleaseMode = isReleaseMode;
Framework = framework;
TargetPlatform = targetPlatform;
PackageVersion = packageVersion;
}
}

Expand Down
2 changes: 2 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
& bash $ScriptPath --install-dir "$InstallPath" --channel 2.1 --no-path
& bash $ScriptPath --install-dir "$InstallPath" --channel 3.1 --no-path
& bash $ScriptPath --install-dir "$InstallPath" --channel 5.0 --no-path
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path

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

Remove-PathVariable "$InstallPath"
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
# | arm64 | x64 | x64 | arm64 |
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 2.1 --architecture x64 --install-dir .dotnet --no-path
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 3.1 --architecture x64 --install-dir .dotnet --no-path
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 5.0 --architecture x64 --install-dir .dotnet --no-path
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
export PATH="$SCRIPT_DIR/.dotnet":$PATH
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
Expand Down
88 changes: 88 additions & 0 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,27 @@ functions:
SSL=${SSL} \
evergreen/run-serverless-tests.sh
run-smoke-tests:
- command: shell.exec
type: test
params:
working_dir: mongo-csharp-driver
script: |
set +x
${PREPARE_SHELL}
OS=${OS} \
AUTH=${AUTH} \
SSL=${SSL} \
MONGODB_URI="${MONGODB_URI}" \
TOPOLOGY=${TOPOLOGY} \
OS=${OS} \
COMPRESSOR=${COMPRESSOR} \
CLIENT_PEM=${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem \
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
TARGET="SmokeTests" \
FRAMEWORK=${FRAMEWORK} \
evergreen/run-tests.sh
create-serverless-instance:
- command: shell.exec
params:
Expand Down Expand Up @@ -1210,6 +1231,41 @@ tasks:
OCSP_ALGORITHM: "rsa"
OCSP_TLS_SHOULD_SUCCEED: "false"

- name: test-smoke-tests-net472
commands:
- func: bootstrap-mongo-orchestration
- func: run-smoke-tests
vars:
FRAMEWORK: net472

- name: test-smoke-tests-netcoreapp21
commands:
- func: bootstrap-mongo-orchestration
- func: run-smoke-tests
vars:
FRAMEWORK: netcoreapp21

- name: test-smoke-tests-netcoreapp31
commands:
- func: bootstrap-mongo-orchestration
- func: run-smoke-tests
vars:
FRAMEWORK: netcoreapp31

- name: test-smoke-tests-net50
commands:
- func: bootstrap-mongo-orchestration
- func: run-smoke-tests
vars:
FRAMEWORK: net50

- name: test-smoke-tests-net60
commands:
- func: bootstrap-mongo-orchestration
- func: run-smoke-tests
vars:
FRAMEWORK: net60

# ECDSA tests
# Disabled until https://jira.mongodb.org/browse/SPEC-1589 is resolved
# - name: test-ocsp-ecdsa-valid-cert-server-staples-ca-responder
Expand Down Expand Up @@ -1820,3 +1876,35 @@ buildvariants:
batchtime: 20160 # 14 days
tasks:
- name: testgcpkms-task-group
- name: test-csfle-with-mongocryptd-netstandard21

- matrix_name: "smoke-tests-windows"
matrix_spec: { os: "windows-64", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
display_name: "smoke-tests ${version} ${os}"
batchtime: 1440 # 1 day
tasks:
- name: test-smoke-tests-net472
- name: test-smoke-tests-netcoreapp21
- name: test-smoke-tests-netcoreapp31
- name: test-smoke-tests-net50
- name: test-smoke-tests-net60

- matrix_name: "smoke-tests-linux"
matrix_spec: { os: "ubuntu-1804", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
display_name: "smoke-tests ${version} ${os}"
batchtime: 1440 # 1 day
tasks:
- name: test-smoke-tests-netcoreapp21
- name: test-smoke-tests-netcoreapp31
- name: test-smoke-tests-net50
- name: test-smoke-tests-net60

- matrix_name: "smoke-tests-macOS"
matrix_spec: { os: "macos-1100", ssl: "nossl", version: [ "5.0", "6.0", "latest" ], topology: ["replicaset"] }
display_name: "smoke-tests ${version} ${os}"
batchtime: 1440 # 1 day
tasks:
- name: test-smoke-tests-netcoreapp21
- name: test-smoke-tests-netcoreapp31
- name: test-smoke-tests-net50
- name: test-smoke-tests-net60
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Diagnostics;
using FluentAssertions;

namespace MongoDB.Driver.SmokeTests.Sdk
{
internal static class InfrastructureUtilities
{
public static void ValidateMongoDBPackageVersion()
{
var packageShaExpected = Environment.GetEnvironmentVariable("SmokeTestsPackageSha");

if (!string.IsNullOrEmpty(packageShaExpected))
{
var fileVersionInfo = FileVersionInfo.GetVersionInfo(typeof(MongoClient).Assembly.Location);

fileVersionInfo.ProductVersion.Contains(packageShaExpected)
.Should().BeTrue("Expected package sha {0} in {1}", packageShaExpected, fileVersionInfo.ProductVersion);
}
}
}
}
35 changes: 35 additions & 0 deletions tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LogEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Microsoft.Extensions.Logging;

namespace MongoDB.Driver.SmokeTests.Sdk
{
internal struct LogEntry
{
public LogEntry(LogLevel logLevel, string category, string message)
{
LogLevel = logLevel;
Category = category;
Message = message;
}

public LogLevel LogLevel { get; }
public string Category { get; }
public string Message { get; }

public override string ToString() => $"{LogLevel}_{Category}_{Message}";
}
}
Loading

0 comments on commit 0cf003d

Please sign in to comment.