Skip to content

Commit

Permalink
Update examples after binaryType changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 29, 2024
1 parent 0c7823e commit 3ef1790
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/test-api.k6.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function() {
function startWSWorker(id) {
let url = `wss://test-api.k6.io/ws/crocochat/${chatRoomName}/`;
let ws = new WebSocket(url);
ws.binaryType = "arraybuffer";
ws.addEventListener("open", () => {
ws.send(JSON.stringify({ 'event': 'SET_NAME', 'new_name': `Croc ${__VU}:${id}` }));

Expand Down
18 changes: 9 additions & 9 deletions examples/test-local-echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { setTimeout, clearTimeout, setInterval, clearInterval } from "k6/x/timer

const CLOSED_STATE = 3

export default function () {
export default function() {
// local echo server should be launched with `make ws-echo-server-run`
var url = "ws://localhost:10000";
var params = { "tags": { "my_tag": "hello" } };

let ws = new WebSocket(url, null, params)

ws.binaryType = "arraybuffer";
ws.onopen = () => {
console.log('connected')
ws.send(Date.now().toString())
ws.send(Date.now().toString())
}

let intervalId = setInterval(() => {
ws.ping();
console.log("Pinging every 1 sec (setInterval test)")
}, 1000);

let timeout1id = setTimeout(function () {
let timeout1id = setTimeout(function() {
console.log('2 seconds passed, closing the socket')
clearInterval(intervalId)
ws.close()

}, 2000);

ws.onclose = () => {
Expand All @@ -33,7 +33,7 @@ export default function () {
console.log('disconnected')
}


ws.onping = () => {
console.log("PING!")
}
Expand All @@ -55,7 +55,7 @@ export default function () {
return
}

console.log(`Roundtrip time: ${Date.now() - parsed} ms`);
console.log(`Roundtrip time: ${Date.now() - parsed} ms`);

let timeoutId = setTimeout(function() {
if (ws.readyState == CLOSED_STATE) {
Expand All @@ -67,11 +67,11 @@ export default function () {

ws.send(Date.now().toString())
}, 500);
}
}

ws.onerror = (e) => {
if (e.error != "websocket: close sent") {
console.log('An unexpected error occurred: ', e.error);
}
};
};
};

0 comments on commit 3ef1790

Please sign in to comment.