Skip to content

Commit 4006dfe

Browse files
authored
test: add debug flag for suppressing extra console messages in ssb (#2146)
* test: add debug flag for suppressing extra console messages in ssb * remove unneeded third argument
1 parent 7054e43 commit 4006dfe

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

internal-tooling/performanceTest.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
convertToCSVFormat,
2323
convertToCloudMonitoringFormat,
2424
TestResult,
25+
log,
2526
} from './performanceUtils';
2627
import {existsSync} from 'fs';
2728
import {writeFile} from 'fs/promises';
@@ -72,6 +73,10 @@ const argv = yargs(process.argv.slice(2))
7273
filename: {
7374
type: 'string',
7475
},
76+
debug: {
77+
type: 'boolean',
78+
default: false,
79+
},
7580
})
7681
.parseSync();
7782

@@ -86,8 +91,9 @@ let iterationsRemaining = argv.iterations;
8691
function main() {
8792
let numThreads = argv.numthreads;
8893
if (numThreads > iterationsRemaining) {
89-
console.log(
90-
`${numThreads} is greater than number of iterations (${iterationsRemaining}). Using ${iterationsRemaining} threads instead.`
94+
log(
95+
`${numThreads} is greater than number of iterations (${iterationsRemaining}). Using ${iterationsRemaining} threads instead.`,
96+
argv.debug
9197
);
9298
numThreads = iterationsRemaining;
9399
}
@@ -105,8 +111,9 @@ function main() {
105111
*/
106112
function createWorker() {
107113
iterationsRemaining--;
108-
console.log(
109-
`Starting new iteration. Current iterations remaining: ${iterationsRemaining}`
114+
log(
115+
`Starting new iteration. Current iterations remaining: ${iterationsRemaining}`,
116+
argv.debug
110117
);
111118
let testPath = '';
112119
if (argv.testtype === TRANSFER_MANAGER_TEST_TYPES.WRITE_ONE_READ_THREE) {
@@ -136,15 +143,14 @@ function createWorker() {
136143
});
137144

138145
w.on('message', data => {
139-
console.log('Successfully completed iteration.');
146+
log('Successfully completed iteration.', argv.debug);
140147
recordResult(data);
141148
if (iterationsRemaining > 0) {
142149
createWorker();
143150
}
144151
});
145152
w.on('error', e => {
146-
console.log('An error occurred.');
147-
console.log(e);
153+
log(e, true, true);
148154
});
149155
}
150156

@@ -172,15 +178,15 @@ async function recordResult(results: TestResult[] | TestResult) {
172178
argv.filename,
173179
`${convertToCSVFormat(resultsToAppend)}\n`
174180
)
175-
: console.log(convertToCSVFormat(resultsToAppend));
181+
: log(convertToCSVFormat(resultsToAppend), true);
176182
} else if (argv.format === OUTPUT_FORMATS.CLOUD_MONITORING) {
177183
for await (const outputString of convertToCloudMonitoringFormat(
178184
resultsToAppend,
179185
argv.bucket
180186
)) {
181187
argv.filename
182188
? await appendFile(argv.filename, `${outputString}\n`)
183-
: console.log(outputString);
189+
: log(outputString, true);
184190
}
185191
}
186192
}

internal-tooling/performanceUtils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,20 @@ export function convertToCSVFormat(results: TestResult[]): string {
281281
const csv = results.map(result => Object.values(result));
282282
return csv.join('\n');
283283
}
284+
285+
/**
286+
* Logs the provided message if debugging is enabled.
287+
*
288+
* @param {string | error} messageOrError the message or error object to be printed utilizing console.debug.
289+
* @param {boolean} shouldLog flag indicating whether or not the message should be logged to stdout or stderr.
290+
* @param {boolean} isError if set to true and shouldLog is true, write the output to stderr instead of stdout.
291+
*/
292+
export function log(
293+
messageOrError: string | Error,
294+
shouldLog: boolean,
295+
isError = false
296+
): void {
297+
if (shouldLog) {
298+
isError ? console.error(messageOrError) : console.log(messageOrError);
299+
}
300+
}

0 commit comments

Comments
 (0)