Skip to content

Commit d5d7b24

Browse files
authored
feat(benchmark): Add benchmark scenario for binary files (#10648)
1 parent c97a96d commit d5d7b24

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"createdAt": "2024-09-03T11:51:56.540Z",
3+
"updatedAt": "2024-09-03T12:22:21.000Z",
4+
"name": "Binary Data",
5+
"active": true,
6+
"nodes": [
7+
{
8+
"parameters": {
9+
"httpMethod": "POST",
10+
"path": "binary-files-benchmark",
11+
"responseMode": "responseNode",
12+
"options": {}
13+
},
14+
"type": "n8n-nodes-base.webhook",
15+
"typeVersion": 2,
16+
"position": [0, 0],
17+
"id": "bfe19f12-3655-440f-be5c-8d71665c6353",
18+
"name": "Webhook",
19+
"webhookId": "109d7b13-93ad-42b0-a9ce-ca49e1817b35"
20+
},
21+
{
22+
"parameters": { "respondWith": "binary", "options": {} },
23+
"type": "n8n-nodes-base.respondToWebhook",
24+
"typeVersion": 1.1,
25+
"position": [740, 0],
26+
"id": "cd957c9b-6b7a-4423-aac3-6df4d8bb571e",
27+
"name": "Respond to Webhook"
28+
},
29+
{
30+
"parameters": {
31+
"operation": "write",
32+
"fileName": "=file-{{ Date.now() }}-{{ Math.random() }}.js",
33+
"dataPropertyName": "file",
34+
"options": {}
35+
},
36+
"type": "n8n-nodes-base.readWriteFile",
37+
"typeVersion": 1,
38+
"position": [260, 0],
39+
"id": "f2ce4709-7697-4bc6-8eca-6c222485297a",
40+
"name": "Write File to Disk"
41+
},
42+
{
43+
"parameters": { "fileSelector": "={{ $json.fileName }}", "options": {} },
44+
"type": "n8n-nodes-base.readWriteFile",
45+
"typeVersion": 1,
46+
"position": [500, 0],
47+
"id": "198e8a6c-81a3-4b34-b099-501961a02006",
48+
"name": "Read File from Disk"
49+
}
50+
],
51+
"connections": {
52+
"Webhook": { "main": [[{ "node": "Write File to Disk", "type": "main", "index": 0 }]] },
53+
"Write File to Disk": {
54+
"main": [[{ "node": "Read File from Disk", "type": "main", "index": 0 }]]
55+
},
56+
"Read File from Disk": {
57+
"main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]]
58+
}
59+
},
60+
"settings": { "executionOrder": "v1" },
61+
"staticData": null,
62+
"meta": null,
63+
"pinData": {},
64+
"versionId": "8dd197c0-d1ea-43c3-9f88-9d11e7b081a0",
65+
"triggerCount": 1,
66+
"tags": []
67+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../scenario.schema.json",
3+
"name": "BinaryData",
4+
"description": "Send a binary file to a webhook, write it to FS, read it from FS and receive it back",
5+
"scenarioData": { "workflowFiles": ["binaryData.json"] },
6+
"scriptPath": "binaryData.script.js"
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import http from 'k6/http';
2+
import { check } from 'k6';
3+
4+
const apiBaseUrl = __ENV.API_BASE_URL;
5+
6+
const file = open(__ENV.SCRIPT_FILE_PATH, 'b');
7+
const filename = String(__ENV.SCRIPT_FILE_PATH).split('/').pop();
8+
9+
export default function () {
10+
const data = {
11+
filename,
12+
file: http.file(file, filename, 'application/javascript'),
13+
};
14+
15+
const res = http.post(`${apiBaseUrl}/webhook/binary-files-benchmark`, data);
16+
17+
check(res, {
18+
'is status 200': (r) => r.status === 200,
19+
'has correct content type': (r) =>
20+
r.headers['Content-Type'] === 'application/javascript; charset=utf-8',
21+
});
22+
}

packages/@n8n/benchmark/src/testExecution/k6Executor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function handleSummary(data) {
6060
env: {
6161
API_BASE_URL: this.opts.n8nApiBaseUrl,
6262
K6_CLOUD_TOKEN: this.opts.k6ApiToken,
63+
SCRIPT_FILE_PATH: augmentedTestScriptPath,
6364
},
6465
})`${k6ExecutablePath} run ${flattedFlags} ${augmentedTestScriptPath}`;
6566

@@ -82,7 +83,7 @@ export function handleSummary(data) {
8283

8384
const augmentedTestScript = `${testScript}\n\n${summaryScript}`;
8485

85-
const tempFilePath = tmpfile(`${scenarioRunName}.ts`, augmentedTestScript);
86+
const tempFilePath = tmpfile(`${scenarioRunName}.js`, augmentedTestScript);
8687

8788
return tempFilePath;
8889
}

0 commit comments

Comments
 (0)