Skip to content

fix(e2e) add trace, hardcode down to just one test, flip firstRun to true COMPASS-8166 #6676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions packages/compass-crud/src/stores/crud-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const fetchDocuments: (
options,
executionOptions
) => {
console.log('fetching documents inside crud store, pid ', process.pid);
const canCalculateDocSize =
// $bsonSize is only supported for mongodb >= 4.4.0
semver.gte(serverVersion, '4.4.0') &&
Expand Down
13 changes: 11 additions & 2 deletions packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ async function startCompassElectron(
name: string,
opts: StartCompassOptions = {}
): Promise<Compass> {
console.log('start compass electron...');
runCounter++;
const { testPackagedApp, binary } = await getCompassExecutionParameters();

Expand All @@ -617,6 +618,8 @@ async function startCompassElectron(
'--log-level=0'
);

chromeArgs.push('--host-rules=MAP * 127.0.0.1');

if (opts.extraSpawnArgs) {
chromeArgs.push(...opts.extraSpawnArgs);
}
Expand All @@ -638,7 +641,8 @@ async function startCompassElectron(
// For webdriverio env we are changing appName so that keychain records do not
// overlap with anything else. But leave it alone when testing auto-update.
if (!process.env.HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE) {
process.env.HADRON_PRODUCT_NAME_OVERRIDE = 'MongoDB Compass WebdriverIO';
process.env.HADRON_PRODUCT_NAME_OVERRIDE =
'MongoDB Compassssssss WebdriverIO';
}

// Guide cues might affect too many tests in a way where the auto showing of the cue prevents
Expand Down Expand Up @@ -922,7 +926,11 @@ export async function rebuildNativeModules(
export async function compileCompassAssets(
compassPath = COMPASS_DESKTOP_PATH
): Promise<void> {
await promisify(execFile)('npm', ['run', 'compile'], { cwd: compassPath });
console.log('path nonsense: ', compassPath);
await promisify(execFile)('npm', ['run', 'compile'], {
maxBuffer: 256 * 1024 * 1024,
cwd: compassPath,
});
}

async function getCompassBuildMetadata(): Promise<BinPathOptions> {
Expand Down Expand Up @@ -1035,6 +1043,7 @@ export async function init(
opts: StartCompassOptions = {}
): Promise<Compass> {
name = pathName(name ?? formattedDate());
console.log('process pid inside init: ', process.pid);

// Unfortunately mocha's type is that this.test inside a test or hook is
// optional even though it always exists. So we have a lot of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
};

try {
console.log('unzipping fixtures...');
debug('Unzipping fixtures...');
await gunzip(
// Not using absolute paths because Windows fails to resolve glob
Expand All @@ -71,14 +72,19 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {

debug('X DISPLAY', process.env.DISPLAY);

console.log('line 75 ish');

if (!context.disableStartStop) {
for (const connectionInfo of DEFAULT_CONNECTIONS) {
if (connectionInfo.testServer) {
console.log('cnxn info: ', connectionInfo);
debug(
'Starting MongoDB server for connection %s',
getConnectionTitle(connectionInfo)
);
console.log('85 ish');
const server = await startTestServer(connectionInfo.testServer);
console.log('stgarted test server');
cleanupFns.push(() => {
debug(
'Stopping server for connection %s',
Expand All @@ -90,6 +96,8 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
throwIfAborted();
}

console.log('line 90 ish');

if (isTestingWeb(context) && !isTestingAtlasCloudExternal(context)) {
debug('Starting Compass Web server ...');
if (isTestingAtlasCloudSandbox(context)) {
Expand Down Expand Up @@ -123,6 +131,7 @@ export async function mochaGlobalSetup(this: Mocha.Runner) {
}
}

console.log('mongodb server info');
debug('Getting mongodb server info');
await updateMongoDBServerInfo();

Expand Down
14 changes: 13 additions & 1 deletion packages/compass-e2e-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function main() {
const e2eTestGroup = context.testGroup;
const e2eTestFilter = context.testFilter;

const tests = (
let tests = (
await glob(`tests/**/${e2eTestFilter}.{test,spec}.ts`, {
cwd: __dirname,
})
Expand All @@ -67,6 +67,7 @@ async function main() {
return index >= minGroupIndex && index <= maxGroupIndex;
})
.sort((a, b) => {
// this comment is wrong
// The only test file that's interested in the first-run experience (at the
// time of writing) is time-to-first-query.ts and that happens to be
// alphabetically right at the end. Which is fine, but the first test to run
Expand All @@ -82,18 +83,25 @@ async function main() {
}
});

tests = tests.filter((test) => test === 'tests/no-network-traffic.test.ts');

console.log('test files: ', tests);
debug('Test files:', tests);

if (tests.length === 0) {
throw new Error('No tests to run');
}

console.log('before mocha 1');

const mocha = new Mocha({
timeout: context.mochaTimeout,
bail: context.mochaBail,
reporter: require.resolve('@mongodb-js/mocha-config-compass/reporter'),
});

console.log('after mocha 1');

// @ts-expect-error mocha types are incorrect, global setup this is bound to
// runner, not context
mocha.globalSetup(mochaGlobalSetup);
Expand All @@ -111,9 +119,11 @@ async function main() {
mocha.addFile(path.join(__dirname, testPath));
});

console.log('Running e2e ...');
debug('Running E2E tests');
runnerPromise = new Promise((resolve) => {
mocha.run((failures: number) => {
console.log('on finish??');
debug('Finished running e2e tests', { failures });
process.exitCode = failures ? 1 : 0;
// Since the webdriverio update something is messing with the terminal's
Expand Down Expand Up @@ -161,4 +171,6 @@ async function run() {
await main();
}

console.log('running???????');

void run();
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "npm run typecheck && npm run eslint . && npm run prettier -- --check .",
"depcheck": "depcheck",
"check": "npm run lint && npm run depcheck",
"test": "xvfb-maybe --auto-servernum --server-args=\"-screen 0 1432x840x24\" -- ts-node index.ts",
"test": "ENV DEBUG=*,-electron-rebuild* xvfb-maybe --auto-servernum --server-args=\"-screen 0 1432x840x24\" -- ts-node index.ts",
"test-ci": "npm run test",
"posttest-ci": "npm run coverage-report",
"test-packaged": "npm run test -- --test-packaged-app",
Expand Down
87 changes: 47 additions & 40 deletions packages/compass-e2e-tests/tests/no-network-traffic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';

import http from 'http';
import https from 'https';

/**
* @securityTest Enhanced Network Isolation Tests
*
Expand All @@ -22,11 +25,12 @@ describe('networkTraffic: false / Isolated Edition', function () {
let i = 0;

before(function () {
console.log('an early before in our test of choice');
skipForWeb(this, 'cli params not available in compass-web');

if (process.platform !== 'linux') {
// No strace on other platforms
return this.skip();
// return this.skip();
}
});

Expand Down Expand Up @@ -56,78 +60,81 @@ describe('networkTraffic: false / Isolated Edition', function () {
const wrapperFile = path.join(tmpdir, 'wrap.sh');
await fs.writeFile(
wrapperFile,
`#!/bin/bash\nulimit -c 0; exec strace -f -e connect -qqq -o '${outfile}' '${binary}' "$@"\n`
`#!/bin/bash\nulimit -c 0; '${binary}' "$@"\n`
);
await fs.chmod(wrapperFile, 0o755);
return wrapperFile;
}

console.log('process pid inside no network test: ', process.pid);
const compass = await init(this.test?.fullTitle(), {
extraSpawnArgs: ['--no-network-traffic'],
wrapBinary,
// TODO(COMPASS-8166): firstRun: true seems to result in network traffic.
// Probably the welcome modal.
firstRun: false,
firstRun: true,
});
const browser = compass.browser;

console.log('set up default connections...');
await browser.setupDefaultConnections();

{
// TODO: Remove this once we are including https://github.com/mongodb-js/mongosh/pull/1349
const exitOnDisconnectFile = path.join(tmpdir, 'exitOnDisconnect.js');
await fs.writeFile(
exitOnDisconnectFile,
'process.once("disconnect", () => process.exit())'
'process.once("disconnect", () => {})'
);
console.log('browser.execute...');
await browser.execute((exitOnDisconnectFile) => {
process.env.NODE_OPTIONS ??= '';
process.env.NODE_OPTIONS += ` --require "${exitOnDisconnectFile}"`;
}, exitOnDisconnectFile);
}

try {
console.log('connect to defaults...');
await browser.connectToDefaults();
} finally {
await cleanup(compass);
}

const straceLog = await fs.readFile(outfile, 'utf8');
const connectCalls = straceLog.matchAll(/\bconnect\s*\((?<args>.*)\) =/g);
const connectTargets = new Set<string>();
for (const { groups } of connectCalls) {
const args = groups!.args;
// Possible format for the address argument in 'args':
// sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"
// sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")
// sa_family=AF_INET6, sin6_port=htons(80), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "2606:2800:220:1:248:1893:25c8:1946", &sin6_addr), sin6_scope_id=0
if (!args.includes('AF_INET')) continue;
const match = args.match(
/sa_family=AF_INET6?.*sin6?_port=htons\((?<port>\d+)\).*inet_(addr\("(?<ipv4>[^"]+)"\)|pton\(AF_INET6,\s*"(?<ipv6>[^"]+)")/
)?.groups;
if (!match) {
throw new Error(`Unknown traced connect() target: ${args}`);
}
connectTargets.add(
match.ipv4
? `${match.ipv4}:${match.port}`
: `[${match.ipv6}]:${match.port}`
);
}
// const straceLog = await fs.readFile(outfile, 'utf8');
// const connectCalls = straceLog.matchAll(/\bconnect\s*\((?<args>.*)\) =/g);
// const connectTargets = new Set<string>();
// for (const { groups } of connectCalls) {
// const args = groups!.args;
// // Possible format for the address argument in 'args':
// // sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"
// // sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")
// // sa_family=AF_INET6, sin6_port=htons(80), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "2606:2800:220:1:248:1893:25c8:1946", &sin6_addr), sin6_scope_id=0
// if (!args.includes('AF_INET')) continue;
// const match = args.match(
// /sa_family=AF_INET6?.*sin6?_port=htons\((?<port>\d+)\).*inet_(addr\("(?<ipv4>[^"]+)"\)|pton\(AF_INET6,\s*"(?<ipv6>[^"]+)")/
// )?.groups;
// if (!match) {
// throw new Error(`Unknown traced connect() target: ${args}`);
// }
// connectTargets.add(
// match.ipv4
// ? `${match.ipv4}:${match.port}`
// : `[${match.ipv6}]:${match.port}`
// );
// }

if (
[...connectTargets].some(
(target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
)
) {
throw new Error(`Connected to unexpected host! ${[...connectTargets]}`);
}
if (![...connectTargets].some((target) => /:27091$/.test(target))) {
throw new Error(
`Missed connection to database server in connect trace! ${[
...connectTargets,
]}`
);
}
// const unexpectedHosts = [...connectTargets].filter(
// (target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
// );
// if (unexpectedHosts.length > 0) {
// throw new Error(`Connected to unexpected host! ${[...unexpectedHosts]}`);
// }
// if (![...connectTargets].some((target) => /:27091$/.test(target))) {
// throw new Error(
// `Missed connection to database server in connect trace! ${[
// ...connectTargets,
// ]}`
// );
// }
});
});
3 changes: 3 additions & 0 deletions packages/compass-test-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let isClosed = false;
const clusters = new Map<string, MongoCluster>();
const defaults: MongoClusterOptions = {
topology: 'standalone',
binDir: '/opt/homebrew/bin',
tmpDir: path.join(
os.tmpdir(),
`compass-tests-${hash(process.env.EVERGREEN_TASK_ID ?? '')}`
Expand All @@ -26,8 +27,10 @@ const defaults: MongoClusterOptions = {
export async function startTestServer(
config: Partial<MongoClusterOptions> & { alwaysStartNewServer?: boolean } = {}
): Promise<MongoCluster> {
console.log('29 ish');
const key = JSON.stringify(config);
const existing = !config.alwaysStartNewServer && clusters.get(key);
console.log('here 31');
if (existing && !existing.isClosed()) return existing;
const cluster = await MongoCluster.start({
...defaults,
Expand Down
Loading