Skip to content

Commit b7c235c

Browse files
committed
run smoketests on mac
1 parent 22a9af0 commit b7c235c

File tree

6 files changed

+165
-23
lines changed

6 files changed

+165
-23
lines changed

.evergreen/buildvariants-and-tasks.in.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ const SMOKETEST_BUILD_VARIANTS = [
8080
// run_on: 'rhel80-large',
8181
// depends_on: 'package-rhel',
8282
// },
83-
// {
84-
// name: 'smoketest-macos-x64',
85-
// display_name: 'Smoketest MacOS Intel',
86-
// run_on: 'macos-14',
87-
// depends_on: 'package-macos-x64',
88-
// },
89-
// {
90-
// name: 'smoketest-macos-arm',
91-
// display_name: 'Smoketest MacOS Arm64',
92-
// run_on: 'macos-14-arm64',
93-
// depends_on: 'package-macos-arm',
94-
// }
83+
{
84+
name: 'smoketest-macos-x64',
85+
display_name: 'Smoketest MacOS Intel',
86+
run_on: 'macos-14',
87+
depends_on: 'package-macos-x64',
88+
},
89+
{
90+
name: 'smoketest-macos-arm',
91+
display_name: 'Smoketest MacOS Arm64',
92+
run_on: 'macos-14-arm64',
93+
depends_on: 'package-macos-arm',
94+
}
9595
];
9696
9797
const TEST_PACKAGED_APP_BUILD_VARIANTS = [

.evergreen/buildvariants-and-tasks.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ buildvariants:
8484
variant: package-ubuntu
8585
tasks:
8686
- name: smoketest-compass
87+
- name: smoketest-macos-x64-compass
88+
display_name: Smoketest MacOS Intel (compass)
89+
run_on: macos-14
90+
depends_on:
91+
- name: package-compass
92+
variant: package-macos-x64
93+
tasks:
94+
- name: smoketest-compass
95+
- name: smoketest-macos-arm-compass
96+
display_name: Smoketest MacOS Arm64 (compass)
97+
run_on: macos-14-arm64
98+
depends_on:
99+
- name: package-compass
100+
variant: package-macos-arm
101+
tasks:
102+
- name: smoketest-compass
87103
- name: test-eol-servers
88104
display_name: Test EoL Servers
89105
run_on: ubuntu1804-large
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { SpawnSyncReturns } from 'child_process';
2+
3+
export function assertSpawnSyncResult(
4+
result: SpawnSyncReturns<string>,
5+
name: string
6+
) {
7+
if (result.status === null) {
8+
if (result.signal !== null) {
9+
throw new Error(`${name} terminated due to signal ${result.signal}`);
10+
}
11+
12+
// not supposed to be possible to get here, but just in case
13+
throw new Error(`${name} terminated with no status or signal`);
14+
}
15+
16+
if (result.status !== 0) {
17+
throw new Error(`${name} failed with exit code ${result.status}`);
18+
}
19+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { existsSync } from 'fs';
2+
import { assertSpawnSyncResult } from './helpers';
3+
import type { InstalledAppInfo, Package } from './types';
4+
import { spawnSync } from 'child_process';
5+
6+
function exec(command: string, args: string[]) {
7+
console.log(command, ...args);
8+
9+
assertSpawnSyncResult(
10+
spawnSync(command, args, {
11+
encoding: 'utf8',
12+
stdio: 'inherit',
13+
}),
14+
`${command} ${args.join(' ')}`
15+
);
16+
}
17+
18+
export async function installMacDMG(
19+
appName: string,
20+
{ filepath }: Package
21+
): Promise<InstalledAppInfo> {
22+
const fullDestinationPath = `/Applications/${appName}.app`;
23+
24+
if (existsSync(fullDestinationPath)) {
25+
throw new Error(`${fullDestinationPath} already exists`);
26+
}
27+
28+
exec('hdiutil', ['attach', filepath]);
29+
try {
30+
exec('cp', ['-r', `/Volumes/${appName}/${appName}.app`, '/Applications']);
31+
} finally {
32+
exec('hdiutil', ['detach', `/Volumes/${appName}`]);
33+
}
34+
35+
return Promise.resolve({
36+
appName,
37+
appPath: `/Applications/${appName}.app`,
38+
});
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type Package = {
2+
filename: string;
3+
filepath: string;
4+
};
5+
6+
export type InstalledAppInfo = {
7+
appName: string;
8+
appPath: string;
9+
};

packages/compass-e2e-tests/smoke-test.ts

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env npx ts-node
2+
import { spawnSync } from 'child_process';
23
import { createWriteStream, existsSync, promises as fs } from 'fs';
34
import path from 'path';
45
import yargs from 'yargs';
@@ -7,6 +8,9 @@ import { hideBin } from 'yargs/helpers';
78
import https from 'https';
89
import { pick } from 'lodash';
910
import { handler as writeBuildInfo } from 'hadron-build/commands/info';
11+
import type { InstalledAppInfo, Package } from './installers/types';
12+
import { installMacDMG } from './installers/mac-dmg';
13+
import { assertSpawnSyncResult } from './installers/helpers';
1014

1115
const argv = yargs(hideBin(process.argv))
1216
.scriptName('smoke-tests')
@@ -137,6 +141,10 @@ async function run() {
137141
writeBuildInfo(infoArgs);
138142
const buildInfo = JSON.parse(await fs.readFile(infoArgs.out, 'utf8'));
139143

144+
if (!buildInfoIsCommon(buildInfo)) {
145+
throw new Error('buildInfo is missing');
146+
}
147+
140148
// filter the extensions given the platform (isWindows, isOSX, isUbuntu, isRHEL) and extension
141149
const { isWindows, isOSX, isRHEL, isUbuntu, extension } = context;
142150

@@ -150,9 +158,9 @@ async function run() {
150158

151159
if (!context.skipDownload) {
152160
await Promise.all(
153-
packages.map(async ({ name, filepath }) => {
161+
packages.map(async ({ filename, filepath }) => {
154162
await fs.mkdir(path.dirname(filepath), { recursive: true });
155-
const url = `https://${context.bucketName}.s3.amazonaws.com/${context.bucketKeyPrefix}/${name}`;
163+
const url = `https://${context.bucketName}.s3.amazonaws.com/${context.bucketKeyPrefix}/${filename}`;
156164
console.log(url);
157165
return downloadFile(url, filepath);
158166
})
@@ -162,6 +170,24 @@ async function run() {
162170
verifyPackagesExist(packages);
163171

164172
// TODO(COMPASS-8533): extract or install each package and then test the Compass binary
173+
for (const pkg of packages) {
174+
let appInfo: InstalledAppInfo | undefined = undefined;
175+
176+
console.log('installing', pkg.filepath);
177+
178+
if (pkg.filename.endsWith('.dmg')) {
179+
appInfo = await installMacDMG(buildInfo.productName, pkg);
180+
}
181+
182+
// TODO: all the other installers go here
183+
184+
if (appInfo) {
185+
console.log('testing', appInfo.appPath);
186+
testInstalledApp(appInfo);
187+
} else {
188+
console.log(`no app got installed for ${pkg.filename}`);
189+
}
190+
}
165191
}
166192

167193
function platformFromContext(
@@ -189,6 +215,18 @@ type PackageFilterConfig = Pick<
189215

190216
// subsets of the hadron-build info result
191217

218+
const commonKeys = ['productName'];
219+
type CommonBuildInfo = Record<typeof commonKeys[number], string>;
220+
221+
function buildInfoIsCommon(buildInfo: any): buildInfo is CommonBuildInfo {
222+
for (const key of commonKeys) {
223+
if (!buildInfo[key]) {
224+
return false;
225+
}
226+
}
227+
return true;
228+
}
229+
192230
const windowsFilenameKeys = [
193231
'windows_setup_filename',
194232
'windows_msi_filename',
@@ -245,11 +283,6 @@ function buildInfoIsRHEL(buildInfo: any): buildInfo is RHELBuildInfo {
245283
return true;
246284
}
247285

248-
type Package = {
249-
name: string;
250-
filepath: string;
251-
};
252-
253286
function getFilteredPackages(
254287
compassDir: string,
255288
buildInfo: any,
@@ -282,11 +315,11 @@ function getFilteredPackages(
282315
const extension = config.extension;
283316

284317
return names
285-
.filter((name) => !extension || name.endsWith(extension))
286-
.map((name) => {
318+
.filter((filename) => !extension || filename.endsWith(extension))
319+
.map((filename) => {
287320
return {
288-
name,
289-
filepath: path.join(compassDir, 'dist', name),
321+
filename,
322+
filepath: path.join(compassDir, 'dist', filename),
290323
};
291324
});
292325
}
@@ -333,6 +366,32 @@ function verifyPackagesExist(packages: Package[]): void {
333366
}
334367
}
335368

369+
function testInstalledApp(appInfo: InstalledAppInfo) {
370+
const result = spawnSync(
371+
'npm',
372+
[
373+
'run',
374+
'--unsafe-perm',
375+
'test-packaged',
376+
'--workspace',
377+
'compass-e2e-tests',
378+
'--',
379+
'--test-filter=time-to-first-query',
380+
],
381+
{
382+
encoding: 'utf8',
383+
stdio: 'inherit',
384+
env: {
385+
...process.env,
386+
COMPASS_APP_NAME: appInfo.appName,
387+
COMPASS_APP_PATH: appInfo.appPath,
388+
},
389+
}
390+
);
391+
392+
assertSpawnSyncResult(result, 'npm run test-packaged');
393+
}
394+
336395
run()
337396
.then(function () {
338397
console.log('done');

0 commit comments

Comments
 (0)