Skip to content
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

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 8 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,6 +83,9 @@ 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) {
Expand Down Expand Up @@ -114,6 +118,7 @@ async function main() {
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 +166,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=* 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
97 changes: 60 additions & 37 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,30 @@ import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';

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

// Intercept HTTP requests
const originalHttpRequest = http.request;
http.request = function (...args: any[]) {
console.log('HTTP Request:', args);
return originalHttpRequest.apply(this, args as any);
};

// Intercept HTTPS requests
const originalHttpsRequest = https.request;
https.request = function (...args: any[]) {
console.log('HTTPS Request:', args);
return originalHttpsRequest.apply(this, args as any);
};

// If you want to intercept at an even lower level:
const originalClientRequest = http.ClientRequest;
http.ClientRequest = function () {
console.log('Client Request:', arguments);
return new originalClientRequest(arguments as any);
} as any;

/**
* @securityTest Enhanced Network Isolation Tests
*
Expand Down Expand Up @@ -67,7 +91,7 @@ describe('networkTraffic: false / Isolated Edition', function () {
wrapBinary,
// TODO(COMPASS-8166): firstRun: true seems to result in network traffic.
// Probably the welcome modal.
firstRun: false,
firstRun: true,
});
const browser = compass.browser;

Expand All @@ -92,42 +116,41 @@ describe('networkTraffic: false / Isolated Edition', function () {
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,
// ]}`
// );
// }
});
});
Loading