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

TINY-10708: Suppress bedrock logs in remote testing #142

Merged
merged 11 commits into from
Mar 11, 2024
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Improved

- Reduced progress logs when on CI to 10% intervals #TINY10708
danoaky-tiny marked this conversation as resolved.
Show resolved Hide resolved

## 14.1.2 - 2024-01-31

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion modules/server/src/main/ts/BedrockAuto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const go = (bedrockAutoSettings: BedrockAutoSettings): void => {

return Lifecycle.done(result, webdriver, shutdown(shutdownServices), settings.gruntDone, settings.delayExit);
} catch (e) {
return Lifecycle.error(e, webdriver, shutdown(shutdownServices), settings.gruntDone, settings.delayExit);
return Lifecycle.error(e as any, webdriver, shutdown(shutdownServices), settings.gruntDone, settings.delayExit);
}
}).catch(async (err) => {
// Chalk does not use a formatter. Using node's built-in to expand Objects, etc.
Expand Down
14 changes: 10 additions & 4 deletions modules/server/src/main/ts/bedrock/cli/Hud.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as readline from 'readline';
import * as Env from '../util/Env';

interface ResultData {
readonly done: boolean;
Expand All @@ -25,24 +26,29 @@ export const create = (testfiles: string[], loglevel: 'simple' | 'advanced'): Hu

const writeProgress = (id: string, stopped: boolean, numPassed: number, numSkipped: number, numFailed: number, total: number | '?') => {
const numRun = numPassed + numFailed + numSkipped;
total = total === '?' ? -Infinity : total;
const status = stopped ? (numRun < total ? 'STOPPED' : 'COMPLETE') : 'RUNNING';
stream.write(
'Session: ' + id + ', Status: ' + status + ', Progress: ' + numRun + '/' + total +
', Failed: ' + numFailed + ', Skipped: ' + numSkipped + ' ... ' + '\n'
);
readline.clearLine(stream, 1);
if (!Env.IS_CI) {
readline.clearLine(stream, 1);
}
return Promise.resolve();
};

const advUpdate = (data: ResultData) => {
if (started) {
if (started && !Env.IS_CI) {
// Note, this writes over the above line, which is why we only do this after the first update.
readline.moveCursor(stream, 0, -2);
} else {
started = true;
}
readline.clearLine(stream, 0);
readline.cursorTo(stream, 0);
if (!Env.IS_CI) {
readline.clearLine(stream, 0);
readline.cursorTo(stream, 0);
}
stream.write('Current test: ' + (data.test !== undefined ? data.test.substring(0, 60) : 'Unknown') + '\n');
const totalFiles = data.totalFiles !== undefined ? data.totalFiles : numFiles;
const totalTests = data.totalTests !== undefined ? data.totalTests : totalFiles;
Expand Down
17 changes: 14 additions & 3 deletions modules/server/src/main/ts/bedrock/server/Controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ErrorData } from '@ephox/bedrock-common';
import * as Hud from '../cli/Hud';
import * as Type from '../util/Type';
import * as Env from '../util/Env';

export interface TestErrorData {
readonly data: ErrorData;
Expand Down Expand Up @@ -107,9 +108,16 @@ export const create = (stickyFirstSession: boolean, singleTimeout: number, overa
outputToHud = true;
};

const shouldUpdateHud = (session: TestSession): boolean => {
if (!outputToHud) return false;
if (stickyFirstSession && (timeoutError || session.id !== stickyId)) return false;
if (!Env.IS_CI || session.done) return true;
// Only update the HUD at 10% intervals on remote:
return session.results.length % Math.round(session.totalTests * 0.1) === 0;
};

const updateHud = (session: TestSession) => {
if (!outputToHud) return;
if (stickyFirstSession && (timeoutError || session.id !== stickyId)) return;
if (!shouldUpdateHud(session)) return;
danoaky-tiny marked this conversation as resolved.
Show resolved Hide resolved
const id = session.id;
const numFailed = session.results.reduce((sum, res) => sum + (res.passed || res.skipped ? 0 : 1), 0);
const numSkipped = session.results.reduce((sum, res) => sum + (res.skipped ? 1 : 0), 0);
Expand All @@ -130,7 +138,10 @@ export const create = (stickyFirstSession: boolean, singleTimeout: number, overa
session.updated = Date.now();
session.totalTests = totalTests;
session.done = false;
updateHud(session);
if (!session.results.length || !Env.IS_CI) {
// Update HUD on test starts when in CI only on the very first update i.e. `progress: 0/0`, otherwise skip them.
updateHud(session);
}
};

const recordTestResult = (id: string, name: string, file: string, passed: boolean, time: string, error: TestErrorData | null, skipped: string) => {
Expand Down
1 change: 1 addition & 0 deletions modules/server/src/main/ts/bedrock/util/Env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const IS_CI = 'CI' in process.env && process.stdout.isTTY;
Loading