From 56354151d46faeb242acf7357a7ac8f563e9dc7d Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:21:41 +0300 Subject: [PATCH] test: Add JS CodeNode benchmark scenario (#10632) --- .../jsCodeNodeOnceForEach.json | 97 +++++++++++++++++++ .../jsCodeNodeOnceForEach.manifest.json | 7 ++ .../jsCodeNodeOnceForEach.script.js | 12 +++ 3 files changed, 116 insertions(+) create mode 100644 packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.json create mode 100644 packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.manifest.json create mode 100644 packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.script.js diff --git a/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.json b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.json new file mode 100644 index 000000000..7b89ffde9 --- /dev/null +++ b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.json @@ -0,0 +1,97 @@ +{ + "createdAt": "2024-08-06T12:19:51.268Z", + "updatedAt": "2024-08-06T12:20:45.000Z", + "name": "JS Code Node Once For Each", + "active": true, + "nodes": [ + { + "parameters": { + "httpMethod": "POST", + "path": "code-node-benchmark", + "responseMode": "responseNode", + "options": {} + }, + "type": "n8n-nodes-base.webhook", + "typeVersion": 2, + "position": [0, 0], + "id": "849350b3-4212-4416-a462-1cf331157d37", + "name": "Webhook", + "webhookId": "34ca1895-ccf4-4a4a-8bb8-a042f5edb567" + }, + { + "parameters": { + "respondWith": "allIncomingItems", + "options": {} + }, + "type": "n8n-nodes-base.respondToWebhook", + "typeVersion": 1.1, + "position": [660, 0], + "id": "f0660aa1-8a65-490f-b5cd-f8d134070c13", + "name": "Respond to Webhook" + }, + { + "parameters": { + "category": "randomData", + "randomDataCount": 5 + }, + "type": "n8n-nodes-base.debugHelper", + "typeVersion": 1, + "position": [220, 0], + "id": "50f1efe8-bd2d-4061-9f51-b38c0e3daeb2", + "name": "DebugHelper" + }, + { + "parameters": { + "mode": "runOnceForEachItem", + "jsCode": "// Add new field\n$input.item.json.age = 10 + Math.floor(Math.random() * 30);\n// Mutate existing field\n$input.item.json.password = $input.item.json.password.split('').map(() => '*').join(\"\")\n// Remove field\ndelete $input.item.json.lastname\n// New object field\nconst emailParts = $input.item.json.email.split(\"@\")\n$input.item.json.emailData = {\n user: emailParts[0],\n domain: emailParts[1]\n}\n\nreturn $input.item;" + }, + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [440, 0], + "id": "f9f2f865-e228-403d-8e47-72308359e207", + "name": "OnceForEachItemJSCode" + } + ], + "connections": { + "Webhook": { + "main": [ + [ + { + "node": "DebugHelper", + "type": "main", + "index": 0 + } + ] + ] + }, + "DebugHelper": { + "main": [ + [ + { + "node": "OnceForEachItemJSCode", + "type": "main", + "index": 0 + } + ] + ] + }, + "OnceForEachItemJSCode": { + "main": [ + [ + { + "node": "Respond to Webhook", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "settings": { "executionOrder": "v1" }, + "staticData": null, + "meta": { "templateCredsSetupCompleted": true, "responseMode": "lastNode", "options": {} }, + "pinData": {}, + "versionId": "840a38a1-ba37-433d-9f20-de73f5131a2b", + "triggerCount": 1, + "tags": [] +} diff --git a/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.manifest.json b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.manifest.json new file mode 100644 index 000000000..088e1b6c9 --- /dev/null +++ b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.manifest.json @@ -0,0 +1,7 @@ +{ + "$schema": "../scenario.schema.json", + "name": "CodeNodeJsOnceForEach", + "description": "A JS Code Node that runs once for each item and adds, modifies and removes properties. The data of 5 items is generated using DebugHelper Node, and returned with RespondToWebhook Node.", + "scenarioData": { "workflowFiles": ["jsCodeNodeOnceForEach.json"] }, + "scriptPath": "jsCodeNodeOnceForEach.script.js" +} diff --git a/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.script.js b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.script.js new file mode 100644 index 000000000..e53a35db8 --- /dev/null +++ b/packages/@n8n/benchmark/scenarios/jsCodeNodeOnceForEach/jsCodeNodeOnceForEach.script.js @@ -0,0 +1,12 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +const apiBaseUrl = __ENV.API_BASE_URL; + +export default function () { + const res = http.post(`${apiBaseUrl}/webhook/code-node-benchmark`, {}); + check(res, { + 'is status 200': (r) => r.status === 200, + 'has items in response': (r) => JSON.parse(r.body).length === 5, + }); +}