From ecd8bd2cc7e46e25fae3f64ce37985664ef7f191 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 2 Dec 2024 14:37:03 +1030 Subject: [PATCH] chore: Multiple machine instances per-container --- load-tests/Dockerfile.machine | 3 ++- load-tests/entrypoint.sh | 18 ++++++++++++++++++ load-tests/machine.ts | 1 + load-tests/package-lock.json | 8 ++++---- load-tests/package.json | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100755 load-tests/entrypoint.sh diff --git a/load-tests/Dockerfile.machine b/load-tests/Dockerfile.machine index 143a57bd..474f4737 100644 --- a/load-tests/Dockerfile.machine +++ b/load-tests/Dockerfile.machine @@ -8,7 +8,8 @@ COPY --link package-lock.json ./ RUN npm ci COPY machine.ts ./ +COPY entrypoint.sh ./ RUN npm install -g tsx -CMD ["tsx", "machine.ts"] +CMD ["entrypoint.sh"] diff --git a/load-tests/entrypoint.sh b/load-tests/entrypoint.sh new file mode 100755 index 00000000..49f8674b --- /dev/null +++ b/load-tests/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +PIDS=() + +# Start 20 instances of the machine +for i in $(seq 1 20); do + tsx machine.ts & + echo "Started instance $i" + PIDS+=($!) +done + +# Wait for all instances to finish +for pid in "${PIDS[@]}"; do + wait $pid +done + diff --git a/load-tests/machine.ts b/load-tests/machine.ts index d614bdbc..a2183887 100644 --- a/load-tests/machine.ts +++ b/load-tests/machine.ts @@ -4,6 +4,7 @@ const API_SECRET = process.env.INFERABLE_TEST_API_SECRET const client = new Inferable({ apiSecret: API_SECRET, + machineId: `load-test-${Math.floor(Math.random() * 1000000)}`, }) client.default.register({ diff --git a/load-tests/package-lock.json b/load-tests/package-lock.json index ae4a5a48..2f7bcf12 100644 --- a/load-tests/package-lock.json +++ b/load-tests/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "inferable": "^0.30.55" + "inferable": "^0.30.57" }, "devDependencies": { "@types/node": "^22.10.1", @@ -604,9 +604,9 @@ } }, "node_modules/inferable": { - "version": "0.30.55", - "resolved": "https://registry.npmjs.org/inferable/-/inferable-0.30.55.tgz", - "integrity": "sha512-Re2APc7QcbprPyDyFTUINT8cQ5oDvosyQB1Xn4NnhPc/kGCEmu+YDk6Bc7XQN7VAdLiQodode7issvhrgRIJMg==", + "version": "0.30.57", + "resolved": "https://registry.npmjs.org/inferable/-/inferable-0.30.57.tgz", + "integrity": "sha512-U+lI0DZ3vn9kz8tkqxCn/Q3qEGEQ9XdI3dMHtrGGMOSIvm1hBnPqmLV8hwidr0zfO39l7CJVBItuG25jwLFRhQ==", "license": "MIT", "dependencies": { "@ts-rest/core": "^3.28.0", diff --git a/load-tests/package.json b/load-tests/package.json index 07c603f1..fc292cea 100644 --- a/load-tests/package.json +++ b/load-tests/package.json @@ -10,7 +10,7 @@ }, "homepage": "https://github.com/inferablehq/inferable#readme", "dependencies": { - "inferable": "^0.30.55" + "inferable": "^0.30.57" }, "devDependencies": { "@types/node": "^22.10.1",