Make the server logs more stable by stubbing time and seq info in the log (#53693)

This commit is contained in:
Sheetal Nandi
2023-04-06 16:23:44 -07:00
committed by GitHub
parent 7f6376794e
commit 85f20246a4
842 changed files with 75979 additions and 75967 deletions

View File

@@ -74,7 +74,6 @@ export function createHasErrorMessageLogger(): Logger {
function handleLoggerGroup(logger: Logger, host: TestServerHost | undefined): Logger {
let inGroup = false;
let firstInGroup = false;
let seq = 0;
logger.startGroup = () => {
inGroup = true;
firstInGroup = true;
@@ -88,10 +87,9 @@ function handleLoggerGroup(logger: Logger, host: TestServerHost | undefined): Lo
function msg(s: string, type = ts.server.Msg.Err, write: (s: string) => void) {
s = `[${nowString(logger.host!)}] ${s}`;
if (!inGroup || firstInGroup) s = padStringRight(type + " " + seq.toString(), " ") + s;
if (!inGroup || firstInGroup) s = padStringRight(type + " seq", " ") + s;
if (ts.Debug.isDebugging) console.log(s);
write(s);
if (!inGroup) seq++;
}
function padStringRight(str: string, padding: string) {
@@ -101,8 +99,8 @@ function handleLoggerGroup(logger: Logger, host: TestServerHost | undefined): Lo
function nowString(host: TestServerHost) {
// E.g. "12:34:56.789"
const d = host.now();
return `${ts.padLeft(d.getUTCHours().toString(), 2, "0")}:${ts.padLeft(d.getUTCMinutes().toString(), 2, "0")}:${ts.padLeft(d.getUTCSeconds().toString(), 2, "0")}.${ts.padLeft(d.getUTCMilliseconds().toString(), 3, "0")}`;
host.now(); // To increment the time but not print it to avoid the baseline updates
return `hh:mm:ss:mss`;
}
export function createLoggerWritingToConsole(host: TestServerHost): Logger {
@@ -401,15 +399,22 @@ function patchHostTimeouts(
const originalRunQueuedTimeoutCallbacks = host.runQueuedTimeoutCallbacks;
const originalRunQueuedImmediateCallbacks = host.runQueuedImmediateCallbacks;
const originalSetTime = host.setTime;
let hostDiff: ReturnType<TestServerHost["snap"]> | undefined;
host.runQueuedTimeoutCallbacks = runQueuedTimeoutCallbacks;
host.runQueuedImmediateCallbacks = runQueuedImmediateCallbacks;
host.logTimeoutQueueLength = logTimeoutQueueLength;
host.setTime = setTime;
host.baselineHost = baselineHost;
host.patched = true;
return host;
function setTime(time: number) {
logger.log(`Host is moving to new time`);
return originalSetTime.call(host, time);
}
function logTimeoutQueueLength() {
logger.log(host.timeoutCallbacks.log());
host.baselineHost(host.immediateCallbacks.log());