53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import test from 'brittle'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { createContext, runInContext } from 'node:vm'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const helpersPath = join(__dirname, '../lib/baretop/baretop-ui-helpers.js')
|
|
const composePath = join(__dirname, '../lib/baretop/baretop-compose.js')
|
|
|
|
test('stress synthetic snapshots do not crash compose loop', async (t) => {
|
|
const helpers = await readFile(helpersPath, 'utf8')
|
|
const compose = await readFile(composePath, 'utf8')
|
|
const ctx = createContext({})
|
|
runInContext(helpers + '\n' + compose, ctx)
|
|
|
|
let prevLines = null
|
|
for (let i = 0; i < 120; i++) {
|
|
const huge = Array.from({ length: 1600 }, (_, k) => ({
|
|
pid: k + 1,
|
|
ppid: k % 17,
|
|
name: 'proc-' + k,
|
|
state: k % 2 ? 'run' : 'sleep',
|
|
cpuPct: (k * 7 + i) % 100,
|
|
rssBytes: (k + 1) * 4096
|
|
}))
|
|
const rows = ctx.bareTopSortProcessRows(huge, 'cpu', false, { sortWallMs: 1000 })
|
|
const frame = ['stress-' + i, 'rows=' + rows.length]
|
|
for (const r of rows.slice(0, 500)) {
|
|
frame.push(
|
|
String(r.pid) +
|
|
' ' +
|
|
String(r.name) +
|
|
' cpu=' +
|
|
String(r.cpuPct) +
|
|
' rss=' +
|
|
String(r.rssBytes)
|
|
)
|
|
}
|
|
const em = ctx.bareTopEmitFrame({}, { write() {} }, frame.join('\r\n'), {
|
|
prevLines,
|
|
rows: 46,
|
|
cols: 140,
|
|
incrementalFrameDiff: true,
|
|
useLineHash: true,
|
|
fullscreenPanel: false,
|
|
cup: (r, c) => `\x1b[${r};${c}H`
|
|
})
|
|
prevLines = em.nextLines
|
|
t.ok(Array.isArray(prevLines))
|
|
}
|
|
})
|