diff --git a/build.cake b/build.cake index 0a0dc25ea6c..ceb35a16ca0 100644 --- a/build.cake +++ b/build.cake @@ -150,43 +150,6 @@ Task("TestSocks5Proxy") action: (BuildConfig buildConfig, Path testProject) => RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\"")); -Task("SmokeTests") - .DoesForEach( - GetFiles("./**/SmokeTests/**/*.SmokeTests*.csproj"), - action: (BuildConfig buildConfig, Path testProject) => - { - var environmentVariables = new Dictionary - { - { "SmokeTestsPackageSha", gitVersion.Sha } - }; - - var toolSettings = new DotNetToolSettings { EnvironmentVariables = environmentVariables }; - - Information($"Updating MongoDB package: {buildConfig.PackageVersion} sha: {gitVersion.Sha}"); - - DotNetTool( - testProject.FullPath, - "add package MongoDB.Driver", - $"--no-restore --version [{buildConfig.PackageVersion}]", - toolSettings); - - DotNetTool( - testProject.FullPath, - "add package MongoDB.Driver.Encryption", - $"--no-restore --version [{buildConfig.PackageVersion}]", - toolSettings); - - RunTests( - buildConfig, - testProject, - settings => - { - settings.NoBuild = false; - settings.NoRestore = false; - settings.EnvironmentVariables = environmentVariables; - }); - }); - Setup( setupContext => { diff --git a/evergreen/append-myget-package-source.sh b/evergreen/append-myget-package-source.sh new file mode 100644 index 00000000000..4e788f20be5 --- /dev/null +++ b/evergreen/append-myget-package-source.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# add/adjust nuget.config pointing to myget so intermediate versions could be restored +if [ -f "./nuget.config" ]; then + echo "Adding myget into nuget.config" + NUGET_SOURCES=$(dotnet nuget list source --format short) + if [[ ${NUGET_SOURCES} != *"https://www.myget.org/F/mongodb/api/v3/index.json"* ]];then + dotnet nuget add source https://www.myget.org/F/mongodb/api/v3/index.json -n myget.org --configfile ./nuget.config + fi +else + echo "Creating custom nuget.config" + cat > "nuget.config" << EOL + + + + + + + + +EOL +fi diff --git a/evergreen/compile-sources.sh b/evergreen/compile-sources.sh index 7ff94966057..7b9fe71f717 100644 --- a/evergreen/compile-sources.sh +++ b/evergreen/compile-sources.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -o errexit # Exit the script with error if any of the commands fail +SOURCE_PROJECT=${1:-CSharpDriver.sln} if [ -z "$PACKAGE_VERSION" ]; then PACKAGE_VERSION=$(bash ./evergreen/get-version.sh) echo Calculated PACKAGE_VERSION value: "$PACKAGE_VERSION" @@ -13,7 +14,7 @@ for (( ATTEMPT=1; ATTEMPT<=RESTORE_MAX_RETRIES; ATTEMPT++ )) do echo "Attempt $ATTEMPT of $RESTORE_MAX_RETRIES to run dotnet restore..." exit_status=0 - dotnet restore || exit_status=$? + dotnet restore "${SOURCE_PROJECT}" --verbosity normal || exit_status=$? if [[ "$exit_status" -eq 0 ]]; then echo "dotnet restore succeeded." break @@ -29,4 +30,4 @@ do sleep $DELAY done -dotnet build -c Release --no-restore -p:Version="$PACKAGE_VERSION" +dotnet build "${SOURCE_PROJECT}" -c Release --no-restore -p:Version="$PACKAGE_VERSION" diff --git a/evergreen/evergreen.yml b/evergreen/evergreen.yml index 0028fe35679..ad8995c2704 100644 --- a/evergreen/evergreen.yml +++ b/evergreen/evergreen.yml @@ -728,17 +728,9 @@ functions: script: | set +x ${PREPARE_SHELL} - 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 + evergreen/run-smoke-tests.sh "${PACKAGE_VERSION}" run-test-SK: - command: shell.exec diff --git a/evergreen/run-external-script.sh b/evergreen/run-external-script.sh index fe635425286..9339e898965 100644 --- a/evergreen/run-external-script.sh +++ b/evergreen/run-external-script.sh @@ -11,25 +11,7 @@ echo "Cloning the remote repo..." git clone -b "${GIT_BRANCH:-main}" --single-branch "${GIT_REPO}" . # add/adjust nuget.config pointing to myget so intermediate versions could be restored -if [ -f "./nuget.config" ]; then - echo "Adding myget into nuget.config" - NUGET_SOURCES=$(dotnet nuget list source --format short) - if [[ ${NUGET_SOURCES} != *"https://www.myget.org/F/mongodb/api/v3/index.json"* ]];then - dotnet nuget add source https://www.myget.org/F/mongodb/api/v3/index.json -n myget.org --configfile ./nuget.config - fi -else - echo "Creating custom nuget.config" - cat > "nuget.config" << EOL - - - - - - - - -EOL -fi +. "${PROJECT_DIRECTORY}/evergreen/append-myget-package-source.sh" # make files executable echo "Making files executable" diff --git a/evergreen/run-smoke-tests.sh b/evergreen/run-smoke-tests.sh new file mode 100644 index 00000000000..e0c3313faa3 --- /dev/null +++ b/evergreen/run-smoke-tests.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +SMOKE_TESTS_PROJECT="./tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/MongoDB.Driver.SmokeTests.Sdk.csproj" + +DRIVER_PACKAGE_VERSION="$1" +if [ -z "$DRIVER_PACKAGE_VERSION" ]; then + echo "Driver package version should be provided." + exit 1 +fi + +. ./evergreen/append-myget-package-source.sh + +export DRIVER_PACKAGE_VERSION="${DRIVER_PACKAGE_VERSION}" +. ./evergreen/compile-sources.sh "$SMOKE_TESTS_PROJECT" + +dotnet test "$SMOKE_TESTS_PROJECT" -c Release --no-build -f "$FRAMEWORK" --results-directory ./build/test-results --logger "junit;verbosity=detailed;LogFileName=TEST-{assembly}.xml;FailureBodyFormat=Verbose" --logger "console;verbosity=detailed" diff --git a/evergreen/run-tests.sh b/evergreen/run-tests.sh index 7ee6391a66f..ea9f44678e4 100755 --- a/evergreen/run-tests.sh +++ b/evergreen/run-tests.sh @@ -141,26 +141,6 @@ if [ -f "$DRIVERS_TOOLS/.evergreen/csfle/secrets-export.sh" ]; then source $DRIVERS_TOOLS/.evergreen/csfle/secrets-export.sh fi -if [[ "$TARGET" =~ "SmokeTests" ]]; then - # add/adjust nuget.config pointing to myget so intermediate versions could be restored - if [ -f "./nuget.config" ]; then - echo "Adding myget into nuget.config" - dotnet nuget add source https://www.myget.org/F/mongodb/api/v3/index.json -n myget.org --configfile ./nuget.config - else - echo "Creating custom nuget.config" - cat > "nuget.config" << EOL - - - - - - - - -EOL - fi -fi - . ./evergreen/compile-sources.sh if [[ "$OS" =~ Windows|windows ]]; then powershell.exe .\\build.ps1 --target=$TARGET diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/InfrastructureUtilities.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/InfrastructureUtilities.cs index f76b16ef3aa..c17989efb34 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/InfrastructureUtilities.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/InfrastructureUtilities.cs @@ -17,11 +17,9 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using FluentAssertions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using MongoDB.Driver.Encryption; namespace MongoDB.Driver.SmokeTests.Sdk { @@ -31,23 +29,6 @@ internal static class InfrastructureUtilities Environment.GetEnvironmentVariable("MONGO_URI") ?? "mongodb://localhost"; - public static void ValidateMongoDBPackageVersion() - { - var packageShaExpected = Environment.GetEnvironmentVariable("SmokeTestsPackageSha"); - - if (!string.IsNullOrEmpty(packageShaExpected)) - { - var driverFileVersionInfo = FileVersionInfo.GetVersionInfo(typeof(MongoClient).Assembly.Location); - var libmongocryptFileVersionInfo = FileVersionInfo.GetVersionInfo(typeof(ClientEncryption).Assembly.Location); - - driverFileVersionInfo.ProductVersion?.Contains(packageShaExpected) - .Should().BeTrue("Expected package sha {0} in {1} for driver package version.", packageShaExpected, driverFileVersionInfo.ProductVersion); - - libmongocryptFileVersionInfo.ProductVersion?.Contains(packageShaExpected) - .Should().BeTrue("Expected package sha {0} in {1} for libmongocrypt package version.", packageShaExpected, libmongocryptFileVersionInfo.ProductVersion); - } - } - public static void AssertLogs(LogEntry[] expectedLogs, LogEntry[] actualLogs) { var actualLogIndex = 0; diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs index db3edd2394d..037b9e3b2b8 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs @@ -37,7 +37,6 @@ public class LibmongocryptTests public LibmongocryptTests(ITestOutputHelper output) { - InfrastructureUtilities.ValidateMongoDBPackageVersion(); MongoClientSettings.Extensions.AddAutoEncryption(); _output = output; } diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs index 21e78fea664..13578268a97 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LoggingTests.cs @@ -30,7 +30,6 @@ public sealed class LoggingTests public LoggingTests(ITestOutputHelper output) { - InfrastructureUtilities.ValidateMongoDBPackageVersion(); _output = output; } diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/MongoDB.Driver.SmokeTests.Sdk.csproj b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/MongoDB.Driver.SmokeTests.Sdk.csproj index c089994a4c1..0e18cd037c0 100644 --- a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/MongoDB.Driver.SmokeTests.Sdk.csproj +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/MongoDB.Driver.SmokeTests.Sdk.csproj @@ -10,15 +10,11 @@ ..\..\..\MongoDBTest.ruleset - - true - - - - - - + + + + diff --git a/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ValidatePackagesVersionTests.cs b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ValidatePackagesVersionTests.cs new file mode 100644 index 00000000000..66e50c8683c --- /dev/null +++ b/tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/ValidatePackagesVersionTests.cs @@ -0,0 +1,54 @@ +/* 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.Reflection; +using FluentAssertions; +using MongoDB.Driver.Encryption; +using Xunit; +using Xunit.Sdk; + +namespace MongoDB.Driver.SmokeTests.Sdk +{ + public class ValidatePackagesVersionTests + { + private readonly string _packageVersion; + + public ValidatePackagesVersionTests() + { + _packageVersion = Environment.GetEnvironmentVariable("DRIVER_PACKAGE_VERSION"); + } + + [Fact] + public void ValidateDriverPackageVersion() => + ValidateAssemblyInformationalVersion(typeof(MongoClient).Assembly, _packageVersion); + + [Fact] + public void ValidateEncryptionPackageVersion() => + ValidateAssemblyInformationalVersion(typeof(ClientEncryption).Assembly, _packageVersion); + + private static void ValidateAssemblyInformationalVersion(Assembly assembly, string expectedVersion) + { + if (string.IsNullOrEmpty(expectedVersion)) + { + return; + } + + var assemblyInformationAttribute = assembly.GetCustomAttribute(); + assemblyInformationAttribute.Should().NotBeNull(); + assemblyInformationAttribute.InformationalVersion.Should().StartWith(expectedVersion); + } + } +}