Created
April 22, 2021 10:08
-
-
Save vikas5914/8ff8b25b3045bc110a6704e0d7632237 to your computer and use it in GitHub Desktop.
K6 Load testing Laravel Echo Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ws from 'k6/ws' | |
import { check } from 'k6' | |
export const options = { | |
stages: [ | |
{ duration: '30s', target: 100 }, | |
{ duration: '2m', target: 1000 }, | |
{ duration: '2m', target: 2000 }, | |
{ duration: '2m', target: 3000 }, | |
{ duration: '1m', target: 0 } | |
] | |
} | |
export default function () { | |
const url = 'wss://websocket.kapadiya.net/socket.io/?EIO=4&transport=websocket' | |
const response = ws.connect(url, {}, function (socket) { | |
socket.on('open', function open () { | |
console.log('connected') | |
// socket.send(Date.now()) | |
socket.setInterval(function timeout () { | |
socket.send('3') | |
}, 10000) | |
}) | |
socket.on('message', function incoming (msg) { | |
if (msg && msg.startsWith('0{"sid')) { | |
socket.send( | |
'40/echo-app-key,{"headers":{}}' | |
) | |
} | |
if (msg && msg.startsWith('40/echo-app-key,{"sid":"')) { | |
socket.send( | |
'42/echo-app-key,["subscribe",{"channel":"twitter","auth":{"headers":{}}}]' | |
) | |
} | |
}) | |
socket.on('close', function close () { | |
console.log('disconnected') | |
}) | |
socket.on('error', function (e) { | |
console.log('error', e) | |
if (e.error() != 'websocket: close sent') { | |
console.log('An unexpected error occured: ', e.error()) | |
} | |
}) | |
}) | |
check(response, { 'status is 101': (r) => r && r.status === 101 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment