From e51a7d060c2dc5032cacb93280e41b9e697f8be4 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 1 Dec 2024 15:29:57 +1030 Subject: [PATCH] temp: Break e2e test --- load-tests/2 | 73 ++++++++++++++++++++++++++++++++++++++++++++ load-tests/script.js | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 load-tests/2 diff --git a/load-tests/2 b/load-tests/2 new file mode 100644 index 00000000..0ff3f330 --- /dev/null +++ b/load-tests/2 @@ -0,0 +1,73 @@ +import http from 'k6/http'; +import { sleep, check } from 'k6'; + +// K6 defaults +// export const options = { +// vus: 1, +// iterations: 1, +// }; + +const API_SECRET = __ENV.INFERABLE_TEST_API_SECRET +const CLUSTER_ID = __ENV.INFERABLE_TEST_CLUSTER_ID +const BASE_URL = 'https://api.inferable.ai'; + +export default function () { + if (!API_SECRET || !CLUSTER_ID) { + throw new Error('Missing required environment variables'); + } + + // Create a new run + const postRunResponse = http.post(`${BASE_URL}/clusters/${CLUSTER_ID}/runs`, JSON.stringify({ + initialPrompt: 'Get the special word from the `searchHaystack` function', + resultSchema: { + type: 'object', + properties: { + word: { + type: 'string' + } + } + } + }), { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${API_SECRET}` + } + }); + + check(postRunResponse, { + 'run created': (r) => r.status === 201 + }); + + const runId = postRunResponse.json('id'); + + // Poll the run status until complete or timeout + let attempts = 0; + const maxAttempts = 10; + + while (attempts < maxAttempts) { + const getRunResponse = http.get(`${BASE_URL}/clusters/${CLUSTER_ID}/runs/${runId}`, { + headers: { + 'Authorization': `Bearer ${API_SECRET}` + } + }); + + const run = getRunResponse.json(); + + if (!['running', 'pending'].includes(run.status)) { + + check(run, { + 'run completed': (r) => r.status === 'done' + }); + + check(run, { + 'found needle word': (r) => r.result.word === 'needle2' + }); + + break; + } + + attempts++; + sleep(1); + } + +} diff --git a/load-tests/script.js b/load-tests/script.js index bb8b5be2..0ff3f330 100644 --- a/load-tests/script.js +++ b/load-tests/script.js @@ -60,7 +60,7 @@ export default function () { }); check(run, { - 'found needle word': (r) => r.result.word === 'needle' + 'found needle word': (r) => r.result.word === 'needle2' }); break;