Skip to content

Commit

Permalink
temp: Break e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 1, 2024
1 parent b09c9b6 commit e51a7d0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
73 changes: 73 additions & 0 deletions load-tests/2
Original file line number Diff line number Diff line change
@@ -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);
}

}
2 changes: 1 addition & 1 deletion load-tests/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e51a7d0

Please sign in to comment.