Skip to content

Commit d79e63f

Browse files
committed
Switch the streaming load test from browser to request API
1 parent d5a392c commit d79e63f

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

k6/streaming.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
/* eslint-disable import/no-unresolved */
21
import { check } from 'k6';
3-
import { browser } from 'k6/browser';
4-
/* eslint-enable import/no-unresolved */
2+
import http from 'k6/http';
53
import { defaultOptions, url } from './_util.js';
64

7-
export const options = defaultOptions(true);
5+
export const options = defaultOptions(false);
86

9-
export default async () => {
10-
const streamingUrl = url('stream_async_components?delay=0');
11-
const page = await browser.newPage();
12-
try {
13-
await page.goto(streamingUrl);
14-
await page.waitForFunction(
15-
() => !document.body.textContent.includes('Loading'),
16-
{
17-
// in milliseconds
18-
timeout: 5000,
19-
},
20-
);
21-
check(await page.locator('html').textContent(), {
22-
'has all comments': (text) => {
23-
const commentIds = [1, 2, 3, 4];
24-
return commentIds.every((id) => text.includes(`Comment ${id}`));
25-
},
26-
});
27-
} finally {
28-
await page.close();
29-
}
7+
export default () => {
8+
const streamingUrl = url('stream_async_components?delay=5');
9+
check(http.get(streamingUrl), {
10+
'status was 200': (res) => res.status === 200,
11+
'has all comments': (res) => {
12+
const body = res.html().text();
13+
const commentIds = [1, 2, 3, 4];
14+
const hasAllComments = commentIds.every((commentId) => body.includes(`Comment ${commentId}`));
15+
const hasFailedRequests = !!body.match(/Request to .+ failed/i);
16+
return hasAllComments && !hasFailedRequests;
17+
},
18+
});
3019
};

0 commit comments

Comments
 (0)