From c1fa4fd05c3e9ee139bd83829b4bd5e37f61633a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 4 Mar 2021 16:37:20 +0100 Subject: [PATCH] chore(ci): also test against community server MONGOSH-542 --- .evergreen.yml | 148 ++++++++++++++++++----- packages/build/src/download-mongodb.ts | 11 +- packages/cli-repl/src/smoke-tests-fle.ts | 5 +- packages/cli-repl/test/e2e-fle.spec.ts | 3 +- testing/integration-testing-hooks.ts | 50 +++++++- 5 files changed, 177 insertions(+), 40 deletions(-) diff --git a/.evergreen.yml b/.evergreen.yml index 3325f7b886..eb22f11b1e 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -104,7 +104,7 @@ functions: ### # ARTIFACT COMPILATION - # + # # compile_artifact generates the executable binary and uploads it as TGZ to S3 for later use. # Use download_compiled_artifact to download the TGZ from S3. # @@ -142,7 +142,7 @@ functions: ### # E2E TEST EXECUTION - # + # # Runs the E2E tests against the compiled artifact, i.e. expects the compiled artifact to be already present. ### run_e2e_tests: @@ -163,13 +163,13 @@ functions: # package_and_upload_artifact generates a distributable package out of the compiled artifact, # i.e. it expects it to have been downloaded already. The distributable package will be uploaded # to a specifc Evergreen S3 bucket for later use. - # + # # The URL to download the distributable package can be retrieved by get_artifact_url. # # package_and_upload_artifact expects the following arguments: # - distro_id # - distribution_build_variant - # + # # get_artifact_url expects the following arguments: # - distribution_build_variant ### @@ -356,8 +356,21 @@ tasks: ### # UNIT TESTS + # E.g. test_m40xc_n12 stands for mongod 4.0.x, community edition, Node.js 12 ### - - name: test_m40x_n12 + - name: test_m40xc_n12 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "12.20.0" + - func: test + vars: + mongosh_server_test_version: "4.0.x-community" + node_js_version: "12.20.0" + mongosh_skip_node_version_check: "1" + - name: test_m40xe_n12 tags: ["unit-test"] commands: - func: checkout @@ -369,7 +382,19 @@ tasks: mongosh_server_test_version: "4.0.x" node_js_version: "12.20.0" mongosh_skip_node_version_check: "1" - - name: test_m42x_n12 + - name: test_m42xc_n12 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "12.20.0" + - func: test + vars: + mongosh_server_test_version: "4.2.x-community" + node_js_version: "12.20.0" + mongosh_skip_node_version_check: "1" + - name: test_m42xe_n12 tags: ["unit-test"] commands: - func: checkout @@ -381,7 +406,19 @@ tasks: mongosh_server_test_version: "4.2.x" node_js_version: "12.20.0" mongosh_skip_node_version_check: "1" - - name: test_m44x_n12 + - name: test_m44xc_n12 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "12.20.0" + - func: test + vars: + mongosh_server_test_version: "4.4.x-community" + node_js_version: "12.20.0" + mongosh_skip_node_version_check: "1" + - name: test_m44xe_n12 tags: ["unit-test"] commands: - func: checkout @@ -405,7 +442,18 @@ tasks: mongosh_server_test_version: "latest-alpha" node_js_version: "12.20.0" mongosh_skip_node_version_check: "1" - - name: test_m40x_n14 + - name: test_m40xc_n14 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "14.15.1" + - func: test + vars: + mongosh_server_test_version: "4.0.x-community" + node_js_version: "14.15.1" + - name: test_m40xe_n14 tags: ["unit-test"] commands: - func: checkout @@ -416,7 +464,18 @@ tasks: vars: mongosh_server_test_version: "4.0.x" node_js_version: "14.15.1" - - name: test_m42x_n14 + - name: test_m42xc_n14 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "14.15.1" + - func: test + vars: + mongosh_server_test_version: "4.2.x-community" + node_js_version: "14.15.1" + - name: test_m42xe_n14 tags: ["unit-test"] commands: - func: checkout @@ -427,7 +486,18 @@ tasks: vars: mongosh_server_test_version: "4.2.x" node_js_version: "14.15.1" - - name: test_m44x_n14 + - name: test_m44xc_n14 + tags: ["unit-test"] + commands: + - func: checkout + - func: install + vars: + node_js_version: "14.15.1" + - func: test + vars: + mongosh_server_test_version: "4.4.x-community" + node_js_version: "14.15.1" + - name: test_m44xe_n14 tags: ["unit-test"] commands: - func: checkout @@ -636,7 +706,7 @@ tasks: vars: node_js_version: "14.15.1" distribution_build_variant: win32msi - + ### # SMOKE TESTS ### @@ -767,7 +837,7 @@ tasks: source_distribution_build_variant: darwin - func: write_preload_script - func: test_artifact_macos - + ### # RELEASE TASKS ### @@ -816,13 +886,19 @@ buildvariants: executable_os_id: darwin tasks: - name: check - - name: test_m40x_n12 - - name: test_m42x_n12 - - name: test_m44x_n12 + - name: test_m40xc_n12 + - name: test_m40xe_n12 + - name: test_m42xc_n12 + - name: test_m42xe_n12 + - name: test_m44xc_n12 + - name: test_m44xe_n12 - name: test_mlatest_n12 - - name: test_m40x_n14 - - name: test_m42x_n14 - - name: test_m44x_n14 + - name: test_m40xc_n14 + - name: test_m40xe_n14 + - name: test_m42xc_n14 + - name: test_m42xe_n14 + - name: test_m44xc_n14 + - name: test_m44xe_n14 - name: test_mlatest_n14 - name: compile_artifact - name: e2e_tests_darwin @@ -834,13 +910,19 @@ buildvariants: executable_os_id: linux tasks: - name: check - - name: test_m40x_n12 - - name: test_m42x_n12 - - name: test_m44x_n12 + - name: test_m40xc_n12 + - name: test_m40xe_n12 + - name: test_m42xc_n12 + - name: test_m42xe_n12 + - name: test_m44xc_n12 + - name: test_m44xe_n12 - name: test_mlatest_n12 - - name: test_m40x_n14 - - name: test_m42x_n14 - - name: test_m44x_n14 + - name: test_m40xc_n14 + - name: test_m40xe_n14 + - name: test_m42xc_n14 + - name: test_m42xe_n14 + - name: test_m44xc_n14 + - name: test_m44xe_n14 - name: test_mlatest_n14 - name: test_vscode - name: test_connectivity @@ -893,13 +975,19 @@ buildvariants: executable_os_id: win32 tasks: - name: check - - name: test_m40x_n12 - - name: test_m42x_n12 - - name: test_m44x_n12 + - name: test_m40xc_n12 + - name: test_m40xe_n12 + - name: test_m42xc_n12 + - name: test_m42xe_n12 + - name: test_m44xc_n12 + - name: test_m44xe_n12 - name: test_mlatest_n12 - - name: test_m40x_n14 - - name: test_m42x_n14 - - name: test_m44x_n14 + - name: test_m40xc_n14 + - name: test_m40xe_n14 + - name: test_m42xc_n14 + - name: test_m42xe_n14 + - name: test_m44xc_n14 + - name: test_m44xe_n14 - name: test_mlatest_n14 - name: e2e_tests_win - name: package_and_upload_artifact_win diff --git a/packages/build/src/download-mongodb.ts b/packages/build/src/download-mongodb.ts index 17a05cde11..6ab4a8af57 100644 --- a/packages/build/src/download-mongodb.ts +++ b/packages/build/src/download-mongodb.ts @@ -115,6 +115,12 @@ export async function downloadMongoDb(tmpdir: string, targetVersionSemverSpecifi return await doDownload(tmpdir, 'latest-alpha', () => lookupAlphaDownloadUrl()); } + let wantsEnterprise = true; + if (/-community$/.test(targetVersionSemverSpecifier)) { + wantsEnterprise = false; + targetVersionSemverSpecifier = targetVersionSemverSpecifier.replace(/-community$/, ''); + } + let fullJson: FullJSON; const fullJSONCachePath = path.resolve(tmpdir, 'full.json.gz'); try { @@ -130,7 +136,10 @@ export async function downloadMongoDb(tmpdir: string, targetVersionSemverSpecifi .filter((info: VersionInfo) => semver.satisfies(info.version, targetVersionSemverSpecifier)) .sort((a: VersionInfo, b: VersionInfo) => semver.rcompare(a.version, b.version)); const versionInfo: VersionInfo = productionVersions[0]; - return await doDownload(tmpdir, versionInfo.version, () => lookupDownloadUrl(versionInfo, true)); + return await doDownload( + tmpdir, + versionInfo.version + (wantsEnterprise ? '-enterprise' : '-community'), + () => lookupDownloadUrl(versionInfo, wantsEnterprise)); } const downloadPromises: Record> = {}; diff --git a/packages/cli-repl/src/smoke-tests-fle.ts b/packages/cli-repl/src/smoke-tests-fle.ts index 977a9b00ec..f1beed6564 100644 --- a/packages/cli-repl/src/smoke-tests-fle.ts +++ b/packages/cli-repl/src/smoke-tests-fle.ts @@ -20,8 +20,9 @@ try { } catch(err) { console.log(err); } -if (db.version().startsWith('4.0.')) { - // No FLE on mongod < 4.2 +if (db.version().startsWith('4.0.') || + !db.runCommand({buildInfo:1}).modules.includes('enterprise')) { + // No FLE on mongod < 4.2 or community print('Test skipped') process.exit(0) } diff --git a/packages/cli-repl/test/e2e-fle.spec.ts b/packages/cli-repl/test/e2e-fle.spec.ts index 4edee2e0ac..58ad77c4d9 100644 --- a/packages/cli-repl/test/e2e-fle.spec.ts +++ b/packages/cli-repl/test/e2e-fle.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { MongoClient } from 'mongodb'; import { TestShell } from './test-shell'; -import { startTestServer, useBinaryPath, skipIfServerVersion } from '../../../testing/integration-testing-hooks'; +import { startTestServer, useBinaryPath, skipIfServerVersion, skipIfCommunityServer } from '../../../testing/integration-testing-hooks'; import { makeFakeHTTPServer, fakeAWSHandlers } from '../../../testing/fake-kms'; import { once } from 'events'; import { serialize } from 'v8'; @@ -11,6 +11,7 @@ import path from 'path'; describe('FLE tests', () => { const testServer = startTestServer('shared'); skipIfServerVersion(testServer, '< 4.2'); // FLE only available on 4.2+ + skipIfCommunityServer(testServer); // FLE is enterprise-only useBinaryPath(testServer); // Get mongocryptd in the PATH for this test let kmsServer: ReturnType; let dbname: string; diff --git a/testing/integration-testing-hooks.ts b/testing/integration-testing-hooks.ts index 238267c882..3591c419f0 100644 --- a/testing/integration-testing-hooks.ts +++ b/testing/integration-testing-hooks.ts @@ -195,6 +195,7 @@ export class MongodSetup { _connectionString: Promise; _setConnectionString: (connectionString: string) => void; _serverVersion: string | null = null; + _isCommunityServer: boolean | null = null; _bindir = ''; constructor(connectionString?: string) { @@ -238,13 +239,31 @@ export class MongodSetup { return this._serverVersion; } + const { version } = await this.withClient(async client => { + return await client.db('db1').admin().serverStatus(); + }); + this._serverVersion = version; + return version; + } + + async isCommunityServer(): Promise { + if (this._isCommunityServer !== null) { + return this._isCommunityServer; + } + + const { modules } = await this.withClient(async client => { + return await client.db('db1').admin().command({ buildInfo: 1 }); + }); + const isCommunityServer = !modules.includes('enterprise'); + this._isCommunityServer = isCommunityServer; + return isCommunityServer; + } + + async withClient(fn: (client: MongoClient) => Promise): Promise { let client; try { client = await MongoClient.connect(await this.connectionString(), {}); - - const { version } = await client.db('db1').admin().serverStatus(); - this._serverVersion = version; - return version; + return await fn(client); } finally { if (client) { client.close(); @@ -340,6 +359,10 @@ async function getInstalledMongodVersion(): Promise { export async function ensureMongodAvailable(mongodVersion = process.env.MONGOSH_SERVER_TEST_VERSION): Promise { try { + if (/-community/.test(String(mongodVersion))) { + console.info(`Explicitly requesting community server with ${mongodVersion}, downloading...`); + throw new Error(); + } const version = await getInstalledMongodVersion(); if (mongodVersion && !semver.satisfies(version, mongodVersion)) { console.info(`global mongod is ${version}, wanted ${mongodVersion}, downloading...`); @@ -439,7 +462,7 @@ function skipIfVersion(test: any, testServerVersion: string, semverCondition: st * condition. * * describe('...', () => { - * ie. skipIfServerVersion(testServer, '< 4.4') + * e.g. skipIfServerVersion(testServer, '< 4.4') * }); */ export function skipIfServerVersion(server: MongodSetup, semverCondition: string): void { @@ -448,6 +471,21 @@ export function skipIfServerVersion(server: MongodSetup, semverCondition: string }); } +/** + * Skip tests in the suite if the test server is a community server. + * + * describe('...', () => { + * e.g. skipIfCommunityServer(testServer) + * }); + */ +export function skipIfCommunityServer(server: MongodSetup): void { + before(async function() { + if (await server.isCommunityServer()) { + this.skip(); + } + }); +} + /** * Add the server tarball's bin/ directrory to the PATH for this section. * This enables using e.g. mongocryptd if available. @@ -496,7 +534,7 @@ export function skipIfEnvServerVersion(semverCondition: string): void { testServerVersion = '9999.9999.9999'; } } else { - testServerVersion = testServerVersion.split('.') + testServerVersion = testServerVersion.split('-')[0].split('.') .map(num => /[0-9]+/.test(num) ? num : '0') .join('.'); }