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

Feature/implement timeouts #154

Merged
merged 12 commits into from
Apr 29, 2021
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ml-testing-toolkit",
"description": "Testing Toolkit for Mojaloop implementations",
"version": "11.13.4",
"version": "11.13.5",
"license": "Apache-2.0",
"author": "Vijaya Kumar Guthi, ModusBox Inc. ",
"contributors": [
Expand Down
2 changes: 2 additions & 0 deletions spec_files/user_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"CLIENT_MUTUAL_TLS_ENABLED": false,
"ADVANCED_FEATURES_ENABLED": true,
"CALLBACK_TIMEOUT": 10000,
"DEFAULT_REQUEST_TIMEOUT": 3000,
"SCRIPT_TIMEOUT": 5000,
"LOG_SERVER_UI_URL": "http://dev1-efk.mojaloop.live/app/kibana",
"UI_CONFIGURATION": {
"MOBILE_SIMULATOR": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/callbackHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const handleCallback = async (callbackObject, context, req) => {
path: callbackObject.path,
headers: callbackObject.headers,
data: callbackObject.body,
timeout: 3000,
timeout: userConfig.DEFAULT_REQUEST_TIMEOUT || 3000,
...httpsProps
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib/scripting-engines/vm-javascript-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ const generateContextObj = async (environmentObj = {}) => {
websocket,
console: consoleFn,
custom: customFn,
consoleOutObj
consoleOutObj,
userConfig
}
return contextObj
}
Expand All @@ -160,12 +161,13 @@ const executeAsync = async (script, data, contextObj) => {
}

try {
await Sandbox.runInNewContext(fullScript, contextObj, { timeout: 30000, microtaskMode: 'afterEvaluate' })
const options = { timeout: (contextObj.userConfig && contextObj.userConfig.SCRIPT_TIMEOUT) || 30000, microtaskMode: 'afterEvaluate' }
await Sandbox.runInNewContext(fullScript, contextObj, options)
for (let i = 0; i < contextObj.consoleOutObj.stdOut.length; i++) {
consoleLog.push([{ execution: 0 }, 'log', ...contextObj.consoleOutObj.stdOut[i]])
}
} catch (err) {
// console.log(err)
console.log(err)
for (let i = 0; i < contextObj.consoleOutObj.stdOut.length; i++) {
consoleLog.push([{ execution: 0 }, 'log', ...contextObj.consoleOutObj.stdOut[i]])
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/test-outbound/outbound-initiator.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ const sendRequest = (baseUrl, method, path, queryParams, headers, body, successC
params: queryParams,
headers: headers,
data: body,
timeout: (contextObj.requestVariables && contextObj.requestVariables.REQUEST_TIMEOUT) || 3000,
timeout: (contextObj.requestVariables && contextObj.requestVariables.REQUEST_TIMEOUT) || userConfig.DEFAULT_REQUEST_TIMEOUT,
validateStatus: function (status) {
return status < 900 // Reject only if the status code is greater than or equal to 900
},
Expand Down
14 changes: 9 additions & 5 deletions src/lib/webSocketClient/WebSocketClientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class WebSocketClientManager {
}

getMessage (clientName, timeout = 5000) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
if (!this.ws[clientName]) {
resolve(null)
} else {
Expand All @@ -118,10 +118,14 @@ class WebSocketClientManager {
var timer = null
// Set the timer
timer = setTimeout(() => {
this.ws[clientName].eventEmitter.removeAllListeners('newMessage')
// Disconnect the websocket connection
this.disconnect(clientName)
resolve(null)
try {
this.ws[clientName].eventEmitter.removeAllListeners('newMessage')
// Disconnect the websocket connection
this.disconnect(clientName)
resolve(null)
} catch (err) {
reject(err)
}
}, timeout)
// Listen for message
this.ws[clientName].eventEmitter.once('newMessage', (message) => {
Expand Down