-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_k6.js
53 lines (46 loc) · 1.26 KB
/
example_k6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import ws from 'k6/ws';
import { sleep } from 'k6';
export default function () {
var url = 'ws://localhost:81/connect';
populateData(url);
}
function populateData(url) {
ws.connect(url, null, function (socket) {
socket.on('open', function () {
console.log("WebSocket connection established.");
addTop(socket, 'key1', new Date().getTime().toString() + 'somereallylongvaluesomereallylongvaluesomereallylongvaluesomereallylongvaluesomereallylongvaluesomereallylongvalue');
addBottom(socket, 'key2', new Date().getTime().toString());
addTop(socket, 'key3', new Date().getTime().toString());
addBottom(socket, 'key4', new Date().getTime().toString());
addTop(socket, 'key5', new Date().getTime().toString());
addBottom(socket, 'key6', new Date().getTime().toString());
close(socket);
});
});
}
function close(socket) {
socket.close();
console.log("WebSocket connection closed.");
}
function addTop(socket, key, value) {
socket.send(JSON.stringify(
{
command: 'addTop',
key: key,
values: [
value
]
}
))
}
function addBottom(socket, key, value) {
socket.send(JSON.stringify(
{
command: 'addBottom',
key: key,
values: [
value
]
}
));
}