Skip to content
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: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/compass-smoke-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@mongodb-js/prettier-config-compass": "^1.2.0",
"@mongodb-js/tsconfig-compass": "^1.2.0",
"depcheck": "^1.4.1",
"debug": "^4.3.4",
"eslint": "^7.25.0",
"hadron-build": "^25.7.0",
"lodash": "^4.17.21",
Expand Down
7 changes: 5 additions & 2 deletions packages/compass-smoke-tests/src/build-info.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import createDebug from 'debug';

import { handler as writeBuildInfo } from 'hadron-build/commands/info';

import { type PackageKind } from './packages';
import { type SmokeTestsContextWithSandbox } from './context';
import { pick } from 'lodash';

const debug = createDebug('compass:smoketests:build-info');

const SUPPORTED_CHANNELS = ['dev', 'beta', 'stable'] as const;

export type Channel = typeof SUPPORTED_CHANNELS[number];
Expand Down Expand Up @@ -242,11 +245,11 @@ export function writeAndReadPackageDetails(
arch: context.arch,
out: path.resolve(context.sandboxPath, 'target.json'),
};
console.log({ infoArgs });
debug({ infoArgs });

// These are known environment variables that will affect the way
// writeBuildInfo works. Log them as a reminder and for our own sanity
console.log(
debug(
'info env vars',
pick(process.env, [
'HADRON_DISTRIBUTION',
Expand Down
11 changes: 7 additions & 4 deletions packages/compass-smoke-tests/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { pick } from 'lodash';
import createDebug from 'debug';
import { SUPPORTED_TESTS } from './tests/types';
import { type SmokeTestsContext } from './context';
import { SUPPORTED_PACKAGES } from './packages';
import { testTimeToFirstQuery } from './tests/time-to-first-query';
import { testAutoUpdateFrom } from './tests/auto-update-from';
import { testAutoUpdateTo } from './tests/auto-update-to';

const debug = createDebug('compass:smoketests');

const SUPPORTED_PLATFORMS = ['win32', 'darwin', 'linux'] as const;
const SUPPORTED_ARCHS = ['x64', 'arm64'] as const;

Expand Down Expand Up @@ -103,9 +106,9 @@ const argv = yargs(hideBin(process.argv))
async function run() {
const context: SmokeTestsContext = argv.parseSync();

console.log(`Running tests`);
debug(`Running tests`);

console.log(
debug(
'context',
pick(context, [
'forceDownload',
Expand All @@ -119,7 +122,7 @@ async function run() {
);

for (const testName of context.tests) {
console.log(testName);
debug(`Running ${testName}`);

if (testName === 'time-to-first-query') {
await testTimeToFirstQuery(context);
Expand All @@ -133,7 +136,7 @@ async function run() {

run()
.then(function () {
console.log('done');
debug('done');
})
.catch(function (err) {
console.error(err.stack);
Expand Down
7 changes: 5 additions & 2 deletions packages/compass-smoke-tests/src/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import stream from 'node:stream';
import createDebug from 'debug';

const debug = createDebug('compass:smoketests:downloads');

import { ensureDownloadsDirectory } from './directories';

Expand Down Expand Up @@ -33,7 +36,7 @@ export async function downloadFile({
if (clearCache) {
fs.rmSync(cacheDirectoryPath, { recursive: true, force: true });
} else {
console.log('Skipped downloading', url, '(cache existed)');
debug('Skipped downloading', url, '(cache existed)');
return outputPath;
}
}
Expand All @@ -44,7 +47,7 @@ export async function downloadFile({

// Write the response to file
assert(response.body, 'Expected a response body');
console.log('Downloading', url);
debug('Downloading', url);
await stream.promises.pipeline(
response.body,
fs.createWriteStream(outputPath)
Expand Down
5 changes: 4 additions & 1 deletion packages/compass-smoke-tests/src/execute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { spawn, spawnSync, type SpawnOptions } from 'node:child_process';
import createDebug from 'debug';

const debug = createDebug('compass:smoketests:execute');

export class ExecuteFailure extends Error {
constructor(
Expand Down Expand Up @@ -34,7 +37,7 @@ export function executeAsync(
options?: SpawnOptions
): Promise<void> {
return new Promise((resolve, reject) => {
console.log(command, ...args);
debug(command, ...args);
const child = spawn(command, args, {
stdio: 'inherit',
...options,
Expand Down
5 changes: 4 additions & 1 deletion packages/compass-smoke-tests/src/installers/mac-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import assert from 'node:assert/strict';
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import createDebug from 'debug';

const debug = createDebug('compass:smoketests:mac-utils');

// TODO: Consider instrumenting the app to use a settings directory in the sandbox
export function removeApplicationSupportForApp(appName: string) {
Expand All @@ -15,7 +18,7 @@ export function removeApplicationSupportForApp(appName: string) {
);

if (fs.existsSync(settingsDir)) {
console.log(`${settingsDir} already exists. Removing.`);
debug(`${settingsDir} already exists. Removing.`);
fs.rmSync(settingsDir, { recursive: true });
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import path from 'node:path';
import createDebug from 'debug';

import type { InstalledAppInfo, InstallablePackage } from './types';
import { execute, ExecuteFailure } from '../execute';

const debug = createDebug('compass:smoketests:windows-msi');

// See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec

export function installWindowsMSI({
Expand All @@ -24,7 +27,7 @@ export function installWindowsMSI({
uninstall();
} catch (err) {
if (err instanceof ExecuteFailure && err.status === 1605) {
console.log(
debug(
"Uninstalling before installing failed, which is expected if the app wasn't already installed"
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import path from 'node:path';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import cp from 'node:child_process';
import createDebug from 'debug';

import type { InstalledAppInfo, InstallablePackage } from './types';
import { execute } from '../execute';
import * as windowsRegistry from './windows-registry';

const debug = createDebug('compass:smoketests:windows-setup');

type UninstallOptions = {
/**
* Expect the app to already be uninstalled, warn if that's not the case.
Expand Down Expand Up @@ -51,7 +54,7 @@ export function installWindowsSetup({
typeof uninstallCommand === 'string',
'Expected an UninstallString in the registry entry'
);
console.log(`Running command to uninstall: ${uninstallCommand}`);
debug(`Running command to uninstall: ${uninstallCommand}`);
cp.execSync(uninstallCommand, { stdio: 'inherit' });
// Removing the any remaining files manually
fs.rmSync(installLocation, { recursive: true, force: true });
Expand Down
9 changes: 6 additions & 3 deletions packages/compass-smoke-tests/src/tests/auto-update-from.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import createDebug from 'debug';
import { type SmokeTestsContext } from '../context';
import { getInstaller } from '../installers';
import { createSandbox } from '../directories';
import { getTestSubject } from '../test-subject';
import { executeAsync } from '../execute';
import { startAutoUpdateServer } from './update-server';

const debug = createDebug('compass:smoketests:auto-update-from');

export async function testAutoUpdateFrom(context: SmokeTestsContext) {
const sandboxPath = createSandbox();
const { kind, appName, filepath, autoUpdatable } = await getTestSubject({
Expand Down Expand Up @@ -61,7 +64,7 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) {
}
);
} finally {
console.log('Stopping auto-update server');
debug('Stopping auto-update server');
server.close();
delete process.env.UPDATE_CHECKER_ALLOW_DOWNGRADES;
}
Expand All @@ -70,9 +73,9 @@ export async function testAutoUpdateFrom(context: SmokeTestsContext) {
}
} finally {
if (context.skipCleanup) {
console.log(`Skipped cleaning up sandbox: ${sandboxPath}`);
debug(`Skipped cleaning up sandbox: ${sandboxPath}`);
} else {
console.log(`Cleaning up sandbox: ${sandboxPath}`);
debug(`Cleaning up sandbox: ${sandboxPath}`);
fs.rmSync(sandboxPath, { recursive: true });
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/compass-smoke-tests/src/tests/auto-update-to.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import createDebug from 'debug';
import { type SmokeTestsContext } from '../context';
import { getInstaller } from '../installers';
import { createSandbox } from '../directories';
Expand All @@ -8,6 +9,8 @@ import { executeAsync } from '../execute';
import { getLatestRelease, getLatestReleaseKindByKind } from '../releases';
import { startAutoUpdateServer } from './update-server';

const debug = createDebug('compass:smoketests:auto-update-to');

export async function testAutoUpdateTo(context: SmokeTestsContext) {
assert(
context.bucketKeyPrefix !== undefined,
Expand Down Expand Up @@ -88,7 +91,7 @@ export async function testAutoUpdateTo(context: SmokeTestsContext) {
}
);
} finally {
console.log('Stopping auto-update server');
debug('Stopping auto-update server');
server.close();
delete process.env.DEV_RELEASE;
delete process.env.PUBLISHED_RELEASES;
Expand All @@ -98,9 +101,9 @@ export async function testAutoUpdateTo(context: SmokeTestsContext) {
}
} finally {
if (context.skipCleanup) {
console.log(`Skipped cleaning up sandbox: ${sandboxPath}`);
debug(`Skipped cleaning up sandbox: ${sandboxPath}`);
} else {
console.log(`Cleaning up sandbox: ${sandboxPath}`);
debug(`Cleaning up sandbox: ${sandboxPath}`);
fs.rmSync(sandboxPath, { recursive: true });
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import fs from 'node:fs';
import createDebug from 'debug';
import { type SmokeTestsContext } from '../context';
import { execute } from '../execute';
import { getInstaller } from '../installers';
import { createSandbox } from '../directories';
import { getTestSubject } from '../test-subject';

const debug = createDebug('compass:smoketests:time-to-first-query');

export async function testTimeToFirstQuery(context: SmokeTestsContext) {
const sandboxPath = createSandbox();
const { kind, appName, filepath } = await getTestSubject({
Expand Down Expand Up @@ -48,9 +51,9 @@ export async function testTimeToFirstQuery(context: SmokeTestsContext) {
}
} finally {
if (context.skipCleanup) {
console.log(`Skipped cleaning up sandbox: ${sandboxPath}`);
debug(`Skipped cleaning up sandbox: ${sandboxPath}`);
} else {
console.log(`Cleaning up sandbox: ${sandboxPath}`);
debug(`Cleaning up sandbox: ${sandboxPath}`);
fs.rmSync(sandboxPath, { recursive: true });
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/compass-smoke-tests/src/tests/update-server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { once } from 'node:events';
import createDebug from 'debug';

const debug = createDebug('compass:smoketests:update-server');

async function importUpdateServer() {
try {
return (await import('compass-mongodb-com')).default;
} catch (err: unknown) {
console.log('Remember to npm link compass-mongodb-com');
debug('Remember to npm link compass-mongodb-com');
throw err;
}
}

export async function startAutoUpdateServer() {
console.log('Starting auto-update server');
debug('Starting auto-update server');
const { httpServer, updateChecker, start } = (await importUpdateServer())();
start();
await once(updateChecker, 'refreshed');
Expand Down
Loading