-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add web socket server load tests
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// cSpell:ignore loadimpact | ||
|
||
import { Counter, Trend } from 'k6/metrics'; | ||
import { check } from 'k6'; | ||
import ws from 'k6/ws'; | ||
|
||
// eslint-disable-next-line no-undef | ||
const { TARGET_ENV, TARGET_NET, WALLETS } = __ENV; | ||
const url = `wss://${TARGET_ENV}-${TARGET_NET}${TARGET_ENV === 'ops' ? '-1' : ''}.lw.iog.io/`; | ||
|
||
export const options = { | ||
ext: { | ||
loadimpact: { | ||
apm: [], | ||
distribution: { 'amazon:us:portland': { loadZone: 'amazon:us:portland', percent: 100 } } | ||
} | ||
}, | ||
scenarios: { | ||
connections: { | ||
executor: 'ramping-vus', | ||
gracefulRampDown: '0s', | ||
gracefulStop: '120s', | ||
stages: [{ duration: '3s', target: Number.parseInt(WALLETS, 10) }], | ||
startVUs: 10 | ||
} | ||
} | ||
}; | ||
|
||
const operationalTrend = new Trend('_operational', true); | ||
const unexpectedCloseCounter = new Counter('_unexpected_close'); | ||
|
||
export const run = () => { | ||
const begin = Date.now(); | ||
|
||
const res = ws.connect(url, null, (socket) => { | ||
let closed = false; | ||
let firstMessage = true; | ||
|
||
socket.on('message', () => { | ||
if (firstMessage) { | ||
operationalTrend.add(Date.now() - begin); | ||
firstMessage = false; | ||
} | ||
}); | ||
|
||
// Count unexpected close | ||
socket.on('close', () => { | ||
if (!closed) unexpectedCloseCounter.add(1); | ||
}); | ||
|
||
// Heartbeat | ||
socket.setTimeout(() => socket.send('{}'), 30 * 1000); | ||
|
||
// End the test after 80" | ||
socket.setTimeout(() => { | ||
closed = true; | ||
socket.close(); | ||
}, 80 * 1000); | ||
}); | ||
|
||
check(res, { 'status is 101': (r) => r && r.status === 101 }); | ||
}; | ||
|
||
export default run; |