Closed savvagen closed 1 year ago
I printed script.config.rocessor
variable type and value, and I got the results for both versions:
console.log(typeof script.config.rocessor)
console.log(script.config.rocessor)
I am getting an error because in the version 1.7.9 we have
object
{
createPeopleCsv: [Function: createPeopleCsv],
saveUsersData: [Function: saveUsersData],
writeUsersDataToCsv: [Function: writeUsersDataToCsv],
userBody: [Function: userBody],
saveUserId: [Function: saveUserId],
postBody: [Function: postBody],
savePost: [Function: savePost],
commentBody: [Function: commentBody],
commentsUpdateBody: [Function: commentsUpdateBody],
getPosts: [Function: getPosts],
getRandomEmail: [Function: getRandomEmail],
getComments: [Function: getComments],
expectationsPluginCheckExpectations: [Function: expectationsPluginCheckExpectations],
expectationsPluginOnError: [Function: expectationsPluginOnError],
expectationsPluginMaybeFlushDatadog: [Function: expectationsPluginMaybeFlushDatadog],
expectationsPluginSetExpectOptions: [Function (anonymous)],
metricsByEndpoint_afterResponse: [Function: metricsByEndpoint_afterResponse]
}
But in artillery@2.0.0-10 we have:
string
../precessors/main.js
thanks for a very detailed issue report @savvagen!
that bit of the plugin API has changed between v1.x and v2.x - Artillery v2 is multi-threaded, but function objects cannot be sent from the main thread to worker threads. That means that plugin need to detect when they're running inside a worker thread, and may only attach code objects (ie functions) directly to the script object then.
Detecting when the plugin is running inside a worker thread is straightforward, that's how the two official plugins you're using do it:
We'll update the docs!
@hassy Can you help me to bypass the error? With what flags or variables should I set to run artillery
inside a worker thread?
@savvagen you need to add a snippet of code to your custom plugin:
if (typeof process.env.LOCAL_WORKER_ID === 'undefined') {
debug('Not running in a worker, exiting');
return;
}
as early as possible, e.g. in the constructor, like the examples I linked earlier
This is available in our documentation now: https://www.artillery.io/docs/reference/extension-apis#attaching-function-objects-to-script-from-a-plugin
Environment:
Preconditions:
Plugin script:
Test script:
Artillery throws an error while running the script: command:
error:
The main reason why it fails, I gues, that in artillery@2.0.0 plugin variable
script.config.processor
is String but not object where we can assign new functions