Skip to content

Commit

Permalink
Fix failures on the pipelines due to memory issues (#1206)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bigmontz authored Jul 23, 2024
1 parent 4d4c579 commit 4e8867c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/testkit-backend/deno/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export function createHandler(
) {
const context = newContext();
const wire = newWire(context, (response) => {
console.log("response:", response);
console.log("response:", response.name);
console.debug(response.data);
return reply(response);
});

for await (const request of requests()) {
console.log("request:", request);
console.log("request:", request.name);
console.debug(request.data);
const { data, name } = request;
if (!(name in requestHandlers)) {
console.log("Unknown request: " + name);
Expand Down
1 change: 1 addition & 0 deletions packages/testkit-backend/deno/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as neo4j } from "../../neo4j-driver-deno/lib/mod.ts";
export { createGetFeatures } from "../src/feature/index.js";
export * as handlers from "../src/request-handlers.js";
export { default as CypherNativeBinders } from "../src/cypher-native-binders.js";
export { default as configurableConsole } from "../src/console.configurable.js";
2 changes: 2 additions & 0 deletions packages/testkit-backend/deno/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
configurableConsole,
Context,
createGetFeatures,
CypherNativeBinders,
Expand Down Expand Up @@ -29,6 +30,7 @@ const logLevel = Deno.env.get("TEST_LOG_LEVEL");
const createContext = () =>
new Context(shouldRunTest, getFeatures, binder, logLevel);

configurableConsole.install(logLevel);
const listener = channel.listen(9876);
const handle = controller.createHandler(neo4j, createContext, requestHandlers);

Expand Down
6 changes: 4 additions & 2 deletions packages/testkit-backend/src/channel/testkit-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ export default class Protocol extends EventEmitter {

serializeResponse (response) {
const responseStr = stringify(response)
console.log('> writing response', responseStr)
console.log('> writing response', response.name)
console.debug(responseStr)
return ['#response begin', responseStr, '#response end'].join('\n') + '\n'
}

_emitRequest () {
const request = JSON.parse(this._request)
const { name, data } = request
console.log('> Got request ' + name, data)
console.log('> Got request ' + name)
console.debug(data)
this.emit('request', { name, data })
}
}
42 changes: 42 additions & 0 deletions packages/testkit-backend/src/console.configurable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const originalConsole = console

const config = {
level: 'info',
canRun: (method) => {
if (config.level === 'debug') {
return true
} else if (config.level === 'info') {
return method !== 'debug'
} else if (config.level === 'warn') {
return method !== 'debug' &&
method !== 'log'
} else if (config.level === 'error') {
return method !== 'debug' &&
method !== 'log' &&
method !== 'warn'
}
return true
}
}

export default {
install (level = 'info') {
this.setLevel(level)
// eslint-disable-next-line no-global-assign
console = new Proxy({}, {
get: (_, method) => (...args) => {
if (config.canRun(method)) {
originalConsole[method].apply(originalConsole, args)
}
}
})
},
setLevel (level) {
config.level = (level || 'info').toLowerCase()
},
uninstall () {
config.level = 'info'
// eslint-disable-next-line no-global-assign
console = originalConsole
}
}
3 changes: 3 additions & 0 deletions packages/testkit-backend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createGetFeatures } from './feature'
import * as REQUEST_HANDLERS from './request-handlers.js'
import * as RX_REQUEST_HANDLERS from './request-handlers-rx.js'
import remoteConsole from './console.remote.js'
import configurableConsole from './console.configurable.js'

const SUPPORTED_TLS = (() => {
if (tls.DEFAULT_MAX_VERSION) {
Expand Down Expand Up @@ -39,6 +40,8 @@ function main () {
const shouldRunTest = getShouldRunTest([...driverDescriptorList, sessionTypeDescriptor])
const getFeatures = createGetFeatures([sessionTypeDescriptor], SUPPORTED_TLS)

configurableConsole.install(process.env.TEST_LOG_LEVEL || 'info')

const newChannel = () => {
if (channelType.toUpperCase() === 'WEBSOCKET') {
const channel = new WebSocketChannel(new URL(`ws://localhost:${backendPort}`))
Expand Down
4 changes: 4 additions & 0 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as responses from './responses.js'
import configurableConsole from './console.configurable.js'

export function throwFrontendError () {
throw new Error('TestKit FrontendError')
Expand Down Expand Up @@ -376,6 +377,9 @@ export function StartTest (_, context, { testName }, wire) {
} else {
context.logLevel = null
}

configurableConsole.setLevel(context.logLevel || context.environmentLogLevel)

const shouldRunTest = context.getShouldRunTestFunction()
shouldRunTest(testName, {
onRun: () => {
Expand Down

0 comments on commit 4e8867c

Please sign in to comment.