curltastic/e2e/load_test.cjs
eros 27e524a418 test: add end-to-end WebSocket test suite
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-24 08:18:16 -07:00

34 lines
1.0 KiB
JavaScript

const WebSocket = require('ws')
const ROOMS = 10
const BASE = 'ws://127.0.0.1:3000/ws?room='
function connect(name, room) {
return new Promise((resolve, reject) => {
const ws = new WebSocket(BASE + room)
ws.on('open', () => resolve(ws))
ws.on('error', reject)
ws.on('message', () => {})
})
}
async function runRoom(i) {
const room = `LOAD${i}`
const p1 = await connect('p1', room)
const p2 = await connect('p2', room)
await new Promise(r => setTimeout(r, 200))
p1.send(JSON.stringify({ type: 'throw', broom_x: 0.2, broom_y: 38.7, weight: 5, curl: 1, friction: 1.0 }))
await new Promise(r => setTimeout(r, 800))
p2.send(JSON.stringify({ type: 'throw', broom_x: -0.1, broom_y: 38.8, weight: 5, curl: 1, friction: 1.0 }))
await new Promise(r => setTimeout(r, 1000))
p1.close()
p2.close()
}
;(async () => {
const start = Date.now()
await Promise.all(Array.from({ length: ROOMS }, (_, i) => runRoom(i)))
console.log(`10 rooms played start-to-throw-to-close in ${Date.now() - start}ms`)
process.exit(0)
})()