Skip to content

Commit c586301

Browse files
authored
Merge 1e44e25 into 7c20d7d
2 parents 7c20d7d + 1e44e25 commit c586301

File tree

6 files changed

+230
-13
lines changed

6 files changed

+230
-13
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"repl": "node tools/repl.js",
3131
"release": "ts-node-script scripts/release/cli.ts",
3232
"pretest": "node tools/pretest.js",
33-
"test": "lerna run --ignore firebase-messaging-integration-test --concurrency 4 --stream test",
34-
"test:ci": "lerna run --ignore firebase-messaging-integration-test --concurrency 4 test:ci",
33+
"test": "lerna run --ignore firebase-messaging-integration-test --stream test",
34+
"test:ci": "lerna run --ignore firebase-messaging-integration-test test:ci",
3535
"pretest:coverage": "mkdirp coverage",
3636
"ci:coverage": "lcov-result-merger 'packages/**/lcov.info' 'lcov-all.info'",
3737
"test:coverage": "lcov-result-merger 'packages/**/lcov.info' | coveralls",

packages/firestore/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"test:lite:browser:debug": "karma start --browsers=Chrome --lite --auto-watch",
2828
"test": "run-s lint test:all",
2929
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all:ci",
30-
"test:all:ci": "run-p test:browser test:lite:browser test:travis",
31-
"test:all": "run-p test:browser test:lite:browser test:travis test:minified",
30+
"test:all:ci": "run-s test:browser test:lite:browser test:travis",
31+
"test:all": "run-s test:browser test:lite:browser test:travis test:minified",
3232
"test:browser": "karma start --single-run",
3333
"test:browser:emulator:debug": "karma start --browsers=Chrome --targetBackend=emulator",
3434
"test:browser:emulator": "karma start --single-run --targetBackend=emulator",

packages/firestore/scripts/run-tests.ts

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,70 @@ import { resolve } from 'path';
2020
import { spawn } from 'child-process-promise';
2121
import * as yargs from 'yargs';
2222

23+
24+
/**
25+
* Creates and returns a "timestamp" string for the elapsed time.
26+
*
27+
* The given timestamp is taken as an offset from the first time that this
28+
* function is invoked. This allows log messages to start at "time 0" and make
29+
* it easy for humans to calculate the elapsed time.
30+
*
31+
* @returns The timestamp string with which to prefix log lines, created from
32+
* the elapsed time since this function's first invocation.
33+
*/
34+
function elapsedTimeStr(): string {
35+
const milliseconds = getElapsedMilliseconds();
36+
const minutes = Math.floor(milliseconds / (1000 * 60));
37+
const seconds = (milliseconds - minutes * 1000 * 60) / 1000;
38+
return (
39+
(minutes < 10 ? '0' : '') +
40+
minutes +
41+
':' +
42+
(seconds < 10 ? '0' : '') +
43+
seconds.toFixed(3)
44+
);
45+
}
46+
47+
/**
48+
* The "start time", which is set to a non-null value upon the first invocation
49+
* of `getElapsedMilliseconds()`. All subsequent invocations calculate the
50+
* elapsed time using this value.
51+
*/
52+
let elapsedMillisecondsStartTime: number | null = null;
53+
54+
/**
55+
* Returns the number of nanoseconds that have elapsed since this function's
56+
* first invocation. Returns 0 on its first invocation.
57+
*/
58+
function getElapsedMilliseconds(): number {
59+
const currentTimeMilliseconds = getCurrentMonotonicTimeMilliseconds();
60+
if (elapsedMillisecondsStartTime === null) {
61+
elapsedMillisecondsStartTime = currentTimeMilliseconds;
62+
return 0;
63+
}
64+
return currentTimeMilliseconds - elapsedMillisecondsStartTime;
65+
}
66+
67+
/**
68+
* Returns the current time, in milliseconds, from a monotonic clock.
69+
*/
70+
function getCurrentMonotonicTimeMilliseconds(): number {
71+
const currentTime: [number, number] = process.hrtime();
72+
return currentTime[0] * 1000 + currentTime[1] / 1_000_000;
73+
}
74+
75+
function debugLog(...args: any[]): void {
76+
// eslint-disable-next-line no-console
77+
console.log(__filename, elapsedTimeStr(), ...args);
78+
}
79+
80+
function errorLog(...args: any[]): void {
81+
// eslint-disable-next-line no-console
82+
console.error(__filename, elapsedTimeStr(), ...args);
83+
}
84+
85+
debugLog(`command-line arguments: ${process.argv.join(' ')}`);
86+
2387
const argv = yargs.options({
2488
main: {
2589
type: 'string',
@@ -58,21 +122,34 @@ let args = [
58122
];
59123

60124
if (argv.emulator) {
125+
debugLog("setting FIRESTORE_TARGET_BACKEND=emulator");
61126
process.env.FIRESTORE_TARGET_BACKEND = 'emulator';
62127
}
63128

64129
if (argv.persistence) {
130+
debugLog("setting USE_MOCK_PERSISTENCE=YES");
65131
process.env.USE_MOCK_PERSISTENCE = 'YES';
66132
args.push('--require', 'test/util/node_persistence.ts');
67133
}
68134

69135
args = args.concat(argv._ as string[]);
70136

137+
debugLog(`spawning child process: ${nyc} ${args.join(' ')}`);
138+
71139
const childProcess = spawn(nyc, args, {
72140
stdio: 'inherit',
73141
cwd: process.cwd()
74142
}).childProcess;
75143

76-
process.once('exit', () => childProcess.kill());
77-
process.once('SIGINT', () => childProcess.kill('SIGINT'));
78-
process.once('SIGTERM', () => childProcess.kill('SIGTERM'));
144+
process.once('exit', () => {
145+
errorLog("WARNING: received 'exit' event; killing child process");
146+
childProcess.kill();
147+
});
148+
process.once('SIGINT', () => {
149+
errorLog("WARNING: received 'SIGINT' event; sending it to child process");
150+
childProcess.kill('SIGINT');
151+
});
152+
process.once('SIGTERM', () => {
153+
errorLog("WARNING: received 'SIGTERM' event; sending it to child process");
154+
childProcess.kill('SIGTERM');
155+
});

packages/firestore/test/integration/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function apiDescribeInternal(
8181
}
8282

8383
for (const enabled of persistenceModes) {
84-
describeFn(`(Persistence=${enabled}) ${message}`, () => testSuite(enabled));
84+
describeFn(`(persistence=${enabled}) ${message}`, () => testSuite(enabled));
8585
}
8686
}
8787

scripts/ci-test/test_changed.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,69 @@ import * as yargs from 'yargs';
2323
import { TestConfig, testConfig } from './testConfig';
2424
const root = resolve(__dirname, '../..');
2525

26+
/**
27+
* Creates and returns a "timestamp" string for the elapsed time.
28+
*
29+
* The given timestamp is taken as an offset from the first time that this
30+
* function is invoked. This allows log messages to start at "time 0" and make
31+
* it easy for humans to calculate the elapsed time.
32+
*
33+
* @returns The timestamp string with which to prefix log lines, created from
34+
* the elapsed time since this function's first invocation.
35+
*/
36+
function elapsedTimeStr(): string {
37+
const milliseconds = getElapsedMilliseconds();
38+
const minutes = Math.floor(milliseconds / (1000 * 60));
39+
const seconds = (milliseconds - minutes * 1000 * 60) / 1000;
40+
return (
41+
(minutes < 10 ? '0' : '') +
42+
minutes +
43+
':' +
44+
(seconds < 10 ? '0' : '') +
45+
seconds.toFixed(3)
46+
);
47+
}
48+
49+
/**
50+
* The "start time", which is set to a non-null value upon the first invocation
51+
* of `getElapsedMilliseconds()`. All subsequent invocations calculate the
52+
* elapsed time using this value.
53+
*/
54+
let elapsedMillisecondsStartTime: number | null = null;
55+
56+
/**
57+
* Returns the number of milliseconds that have elapsed since this function's
58+
* first invocation. Returns 0 on its first invocation.
59+
*/
60+
function getElapsedMilliseconds(): number {
61+
const currentTimeMilliseconds = getCurrentMonotonicTimeMilliseconds();
62+
if (elapsedMillisecondsStartTime === null) {
63+
elapsedMillisecondsStartTime = currentTimeMilliseconds;
64+
return 0;
65+
}
66+
return currentTimeMilliseconds - elapsedMillisecondsStartTime;
67+
}
68+
69+
/**
70+
* Returns the current time, in milliseconds, from a monotonic clock.
71+
*/
72+
function getCurrentMonotonicTimeMilliseconds(): number {
73+
const currentTime: [number, number] = process.hrtime();
74+
return currentTime[0] * 1000 + currentTime[1] / 1_000_000;
75+
}
76+
77+
function debugLog(...args: any[]): void {
78+
// eslint-disable-next-line no-console
79+
console.log(__filename, elapsedTimeStr(), ...args);
80+
}
81+
82+
function errorLog(...args: any[]): void {
83+
// eslint-disable-next-line no-console
84+
console.error(__filename, elapsedTimeStr(), ...args);
85+
}
86+
87+
debugLog(`command-line arguments: ${process.argv.join(' ')}`);
88+
2689
const argv = yargs.parseSync();
2790
const inputTestConfigName = argv._[0].toString();
2891
const testCommand = 'test:ci';
@@ -76,10 +139,14 @@ async function runTests(config: TestConfig) {
76139
}
77140

78141
lernaCmd.push(testCommand);
142+
debugLog(`spawning process: npx ${lernaCmd.join(' ')}`);
79143
await spawn('npx', lernaCmd, { stdio: 'inherit', cwd: root });
144+
debugLog(`process completed successfully: npx ${lernaCmd.join(' ')}`);
80145
process.exit(0);
81146
} catch (e) {
147+
errorLog('process failed');
82148
console.error(chalk`{red ${e}}`);
83-
process.exit(1);
149+
errorLog('terminating with exit code 65');
150+
process.exit(65);
84151
}
85152
}

scripts/run_tests_in_ci.js

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,69 @@ const path = require('path');
2020
const { spawn } = require('child-process-promise');
2121
const { writeFileSync } = require('fs');
2222

23+
/**
24+
* Creates and returns a "timestamp" string for the elapsed time.
25+
*
26+
* The given timestamp is taken as an offset from the first time that this
27+
* function is invoked. This allows log messages to start at "time 0" and make
28+
* it easy for humans to calculate the elapsed time.
29+
*
30+
* @returns The timestamp string with which to prefix log lines, created from
31+
* the elapsed time since this function's first invocation.
32+
*/
33+
function elapsedTimeStr() {
34+
const milliseconds = getElapsedMilliseconds();
35+
const minutes = Math.floor(milliseconds / (1000 * 60));
36+
const seconds = (milliseconds - minutes * 1000 * 60) / 1000;
37+
return (
38+
(minutes < 10 ? '0' : '') +
39+
minutes +
40+
':' +
41+
(seconds < 10 ? '0' : '') +
42+
seconds.toFixed(3)
43+
);
44+
}
45+
46+
/**
47+
* The "start time", which is set to a non-null value upon the first invocation
48+
* of `getElapsedMilliseconds()`. All subsequent invocations calculate the
49+
* elapsed time using this value.
50+
*/
51+
let elapsedMillisecondsStartTime = null;
52+
53+
/**
54+
* Returns the number of nanoseconds that have elapsed since this function's
55+
* first invocation. Returns 0 on its first invocation.
56+
*/
57+
function getElapsedMilliseconds() {
58+
const currentTimeMilliseconds = getCurrentMonotonicTimeMilliseconds();
59+
if (elapsedMillisecondsStartTime === null) {
60+
elapsedMillisecondsStartTime = currentTimeMilliseconds;
61+
return 0;
62+
}
63+
return currentTimeMilliseconds - elapsedMillisecondsStartTime;
64+
}
65+
66+
/**
67+
* Returns the current time, in milliseconds, from a monotonic clock.
68+
*/
69+
function getCurrentMonotonicTimeMilliseconds() {
70+
const currentTime = process.hrtime();
71+
return currentTime[0] * 1000 + currentTime[1] / 1_000_000;
72+
}
73+
74+
function debugLog(...args) {
75+
// eslint-disable-next-line no-console
76+
console.log(__filename, elapsedTimeStr(), ...args);
77+
}
78+
79+
function errorLog(...args) {
80+
// eslint-disable-next-line no-console
81+
console.error(__filename, elapsedTimeStr(), ...args);
82+
}
83+
84+
debugLog(`command-line arguments: ${process.argv.join(' ')}`);
85+
2386
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
2487
// Maps the packages where we should not run `test:all` and instead isolate the cross-browser tests.
2588
// TODO(dwyfrequency): Update object with `storage` and `firestore` packages.
@@ -69,7 +132,10 @@ const argv = yargs.options({
69132
}
70133
}
71134
}
72-
const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);
135+
136+
const yarnArgs = ['--cwd', dir, scriptName];
137+
debugLog(`spawning '${name}' process: yarn ${yarnArgs.join(' ')}`);
138+
const testProcess = spawn('yarn', yarnArgs);
73139

74140
testProcess.childProcess.stdout.on('data', data => {
75141
stdout += data.toString();
@@ -79,13 +145,20 @@ const argv = yargs.options({
79145
});
80146

81147
await testProcess;
82-
console.log('Success: ' + name);
148+
debugLog(
149+
`'${name}' process completed successfully: yarn ${yarnArgs.join(' ')}`
150+
);
83151
writeLogs('Success', name, stdout + '\n' + stderr);
84152
} catch (e) {
85-
console.error('Failure: ' + name);
153+
errorLog(`${name} process FAILED`);
154+
errorLog(`${name} process ==== STDOUT BEGIN ====`);
86155
console.log(stdout);
156+
errorLog(`${name} process ==== STDOUT END ====`);
157+
errorLog(`${name} process ==== STDERR BEGIN ====`);
87158
console.error(stderr);
159+
errorLog(`${name} process ==== STDERR END ====`);
88160
writeLogs('Failure', name, stdout + '\n' + stderr);
89-
process.exit(1);
161+
errorLog('Completing with failure exit code 76');
162+
process.exit(76);
90163
}
91164
})();

0 commit comments

Comments
 (0)