Skip to content

Commit

Permalink
chore(compass-web): refactor sandbox to better handle cert issuing lo…
Browse files Browse the repository at this point in the history
…gic (#6295)

* chore(compass-web): refactor sandbox to better handle cert issuing logic

* chore(web): extend connection timeouts for web sandbox in atlas mode

* chore(web): adjust the logic that waits for the compass web server to be ready

* chore(web): fix typo

* chore(web): electron.dock might be undefined

* chore: restore accidentally removed else

* chore: error logging and typos

* chore: remove unnecessary eslint ignores
  • Loading branch information
gribnoysup authored Sep 30, 2024
1 parent 835a4c5 commit a1d78d9
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 134 deletions.
1 change: 1 addition & 0 deletions configs/webpack-config-compass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,4 @@ export { sharedExternals, pluginExternals };
export { webpackArgsWithDefaults, isServe } from './args';
export { default as webpack } from 'webpack';
export { merge } from 'webpack-merge';
export { default as WebpackDevServer } from 'webpack-dev-server';
40 changes: 27 additions & 13 deletions packages/compass-e2e-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import ResultLogger from './helpers/result-logger';

const debug = Debug('compass-e2e-tests');

const wait = (ms: number) =>
new Promise((resolve) => {
setTimeout(resolve, ms);
});

const allowedArgs = [
'--test-compass-web',
'--no-compile',
Expand Down Expand Up @@ -75,18 +80,27 @@ async function setup() {
},
}
);
// wait for webpack to finish compiling
await new Promise<void>((resolve) => {
let output = '';
const listener = function (chunk: string) {
output += chunk;
if (/^webpack \d+\.\d+\.\d+ compiled/m.test(output)) {
compassWeb.stdout.off('data', listener);
resolve();
}
};
compassWeb.stdout.setEncoding('utf8').on('data', listener);
});

compassWeb.stdout.pipe(process.stdout);
compassWeb.stderr.pipe(process.stderr);

let serverReady = false;
const start = Date.now();
while (!serverReady) {
if (Date.now() - start >= 120_000) {
throw new Error(
'The compass-web sandbox is still not running after 120000ms'
);
}
try {
const res = await fetch('http://localhost:7777');
serverReady = res.ok;
debug('Web server ready: %s', serverReady);
} catch (err) {
debug('Failed to connect to dev server: %s', (err as any).message);
}
await wait(1000);
}
} else {
debug('Writing electron-versions.json');
crossSpawn.sync('scripts/write-electron-versions.sh', [], {
Expand Down Expand Up @@ -131,7 +145,7 @@ function cleanup() {
try {
if (compassWeb.pid) {
debug(`killing compass-web [${compassWeb.pid}]`);
kill(compassWeb.pid);
kill(compassWeb.pid, 'SIGINT');
} else {
debug('no pid for compass-web');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"webpack": "webpack-compass",
"postcompile": "npm run typescript",
"typescript": "tsc -p tsconfig-build.json --emitDeclarationOnly",
"start": "npm run webpack serve -- --mode development",
"start": "electron ./scripts/electron-proxy.js",
"analyze": "npm run webpack -- --mode production --analyze",
"watch": "npm run webpack -- --mode development --watch",
"sync": "node scripts/sync-dist-to-mms.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/compass-web/sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const App = () => {
return (
<SandboxConnectionStorageProviver
value={isAtlas ? null : sandboxConnectionStorage}
extraConnectionOptions={
isAtlas
? // In the sandbox we're waiting for cert user to be propagated to
// the clusters, it can take awhile on the first connection
{ connectTimeoutMS: 120_000, serverSelectionTimeoutMS: 120_000 }
: {}
}
>
<Body as="div" className={sandboxContainerStyles}>
<CompassWeb
Expand Down
Loading

0 comments on commit a1d78d9

Please sign in to comment.