Skip to content

Commit bccbfb9

Browse files
committed
Fix failures on the pipelines due to memory issues
The testkit pipelines are failing given the log size generated from the testkit tests. This PR enables the configuration of log levels for testkit backend ('info' by default) and downgrades the message parameters messages to 'debug' for saving space on logs.
1 parent 4d4c579 commit bccbfb9

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

packages/testkit-backend/src/channel/testkit-protocol.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ export default class Protocol extends EventEmitter {
6262

6363
serializeResponse (response) {
6464
const responseStr = stringify(response)
65-
console.log('> writing response', responseStr)
65+
console.log('> writing response', response.name)
66+
console.debug(responseStr)
6667
return ['#response begin', responseStr, '#response end'].join('\n') + '\n'
6768
}
6869

6970
_emitRequest () {
7071
const request = JSON.parse(this._request)
7172
const { name, data } = request
72-
console.log('> Got request ' + name, data)
73+
console.log('> Got request ' + name)
74+
console.debug(data)
7375
this.emit('request', { name, data })
7476
}
7577
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const originalConsole = console
2+
3+
const config = {
4+
level: 'info',
5+
canRun: (method) => {
6+
if (config.level === 'debug') {
7+
return true
8+
} else if (config.level === 'info') {
9+
return method !== 'debug'
10+
} else if (config.level === 'warn') {
11+
return method !== 'debug' &&
12+
method !== 'log'
13+
} else if (config.level === 'error') {
14+
return method !== 'debug' &&
15+
method !== 'log' &&
16+
method !== 'warn'
17+
}
18+
return true
19+
}
20+
}
21+
22+
export default {
23+
install (level = 'info') {
24+
this.setLevel(level)
25+
// eslint-disable-next-line no-global-assign
26+
console = new Proxy({}, {
27+
get: (_, method) => (...args) => {
28+
if (config.canRun(method)) {
29+
originalConsole[method].apply(originalConsole, args)
30+
}
31+
}
32+
})
33+
},
34+
setLevel (level) {
35+
config.level = (level || 'info').toLowerCase()
36+
},
37+
uninstall () {
38+
config.level = 'info'
39+
// eslint-disable-next-line no-global-assign
40+
console = originalConsole
41+
}
42+
}

packages/testkit-backend/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createGetFeatures } from './feature'
88
import * as REQUEST_HANDLERS from './request-handlers.js'
99
import * as RX_REQUEST_HANDLERS from './request-handlers-rx.js'
1010
import remoteConsole from './console.remote.js'
11+
import configurableConsole from './console.configurable.js'
1112

1213
const SUPPORTED_TLS = (() => {
1314
if (tls.DEFAULT_MAX_VERSION) {
@@ -39,6 +40,8 @@ function main () {
3940
const shouldRunTest = getShouldRunTest([...driverDescriptorList, sessionTypeDescriptor])
4041
const getFeatures = createGetFeatures([sessionTypeDescriptor], SUPPORTED_TLS)
4142

43+
configurableConsole.install(process.env.TEST_LOG_LEVEL || 'info')
44+
4245
const newChannel = () => {
4346
if (channelType.toUpperCase() === 'WEBSOCKET') {
4447
const channel = new WebSocketChannel(new URL(`ws://localhost:${backendPort}`))

packages/testkit-backend/src/request-handlers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as responses from './responses.js'
2+
import configurableConsole from './console.configurable.js'
23

34
export function throwFrontendError () {
45
throw new Error('TestKit FrontendError')
@@ -376,6 +377,9 @@ export function StartTest (_, context, { testName }, wire) {
376377
} else {
377378
context.logLevel = null
378379
}
380+
381+
configurableConsole.setLevel(context.logLevel || context.environmentLogLevel)
382+
379383
const shouldRunTest = context.getShouldRunTestFunction()
380384
shouldRunTest(testName, {
381385
onRun: () => {

0 commit comments

Comments
 (0)