57 lines
1.3 KiB
JavaScript
Executable File
57 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Soak test: connect, query metrics, ping for SOAK_DURATION_MS.
|
|
*
|
|
* Usage:
|
|
* SERVER_PUBLIC_KEY=… SERVER_SEED=… node scripts/soak.js
|
|
*/
|
|
import { PearDataConnection } from '../client/connection.js'
|
|
import { Methods, Pushes } from '../shared/protocol.js'
|
|
|
|
const duration = Number(process.env.SOAK_DURATION_MS) || 60_000
|
|
const publicKey = process.env.SERVER_PUBLIC_KEY
|
|
const seed = process.env.SERVER_SEED
|
|
|
|
if (!publicKey) {
|
|
console.error('SERVER_PUBLIC_KEY required')
|
|
process.exit(1)
|
|
}
|
|
|
|
const conn = new PearDataConnection(publicKey, {
|
|
adminSeed: seed || null,
|
|
timeoutMs: 30_000,
|
|
})
|
|
|
|
let received = 0
|
|
let sent = 0
|
|
let errors = 0
|
|
|
|
conn.on(Pushes.metrics, () => {
|
|
received++
|
|
})
|
|
|
|
await conn.connect()
|
|
console.log('soak connected as', conn.role)
|
|
await conn.request(Methods.subscribeMetrics, { charts: ['*'], intervalMs: 1000 })
|
|
|
|
const end = Date.now() + duration
|
|
while (Date.now() < end) {
|
|
try {
|
|
await conn.request(Methods.queryData, {
|
|
chart: 'system.cpu',
|
|
after: -30,
|
|
points: 30,
|
|
})
|
|
sent++
|
|
await conn.ping()
|
|
} catch (err) {
|
|
errors++
|
|
console.error('soak error', err.message)
|
|
}
|
|
await new Promise((r) => setTimeout(r, Number(process.env.SOAK_INTERVAL_MS) || 500))
|
|
}
|
|
|
|
await conn.destroy()
|
|
console.log(JSON.stringify({ duration, sent, received, errors }, null, 2))
|
|
process.exit(errors > 0 ? 1 : 0)
|