Files
MikrotikManager/backend/scripts/test-mcp-postgres-sharded.mjs
T
DenozordecandClaude Opus 5.5 f857ce9e40 chore(test): вынести NetFlow overlay, удаление WireGuard и приёмки IPsec в шард
Новый шард overlay-ipsec: verifyMcpFlowOverlay, удаление интерфейса WireGuard и
четыре приёмки IPsec (удаление пира, пользователя, сертификата, изменение пира).

Замер: весь набор 272 с (было 334 с), 149 строк результатов совпадают.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 12:46:59 +07:00

51 lines
2.9 KiB
JavaScript

// Runs the primary MCP PostgreSQL integration suite with its slowest self-contained acceptances
// moved to parallel shards. Every process owns a disposable PostgreSQL (test-mcp-postgres.mjs).
// Coverage equals `node scripts/test-mcp-postgres.mjs`: the primary run skips exactly the names
// the shards run (MCP_INTEGRATION_SKIP), and an unknown name fails both sides.
import { spawn } from 'node:child_process'
import { fileURLToPath } from 'node:url'
// Grouped by measured duration (2026-11-19): each shard ~110-190 s, the primary ~320 s.
const shards = {
'scoped-forward': ['acceptScopedRouteCommunitySwitch:forward'],
'scoped-inverse': ['acceptScopedRouteCommunitySwitch:inverse'],
'scoped-route-ai': ['acceptScopedRouteCommunitySwitch:route-ai'],
'wireguard-create': ['acceptWireguardInterfaceCreation', 'acceptRouteCommunityContextMcp', 'acceptWireguardPeerCreation'],
'wireguard-change': ['acceptWireguardInterfaceUpdate', 'acceptWireguardImport'],
'overlay-ipsec': ['verifyMcpFlowOverlay', 'acceptWireguardInterfaceDeletion', 'acceptIpsecPeerDeletion', 'acceptIpsecUserDeletion', 'acceptIpsecCertificateDeletion', 'acceptIpsecPeerUpdate'],
}
const harness = fileURLToPath(new URL('./test-mcp-postgres.mjs', import.meta.url))
const cwd = fileURLToPath(new URL('../', import.meta.url))
const started = performance.now()
const seconds = () => ((performance.now() - started) / 1000).toFixed(0).padStart(4)
function run(label, args, env) {
return new Promise(resolve => {
const child = spawn(process.execPath, [harness, ...args], { cwd, env: { ...process.env, ...env }, stdio: ['ignore', 'pipe', 'pipe'] })
for (const stream of [child.stdout, child.stderr]) {
let pending = ''
stream.setEncoding('utf8')
stream.on('data', chunk => {
const lines = (pending + chunk).split(/\r?\n/)
pending = lines.pop()
for (const line of lines) if (line) console.log(`${seconds()}s [${label}] ${line}`)
})
stream.on('end', () => { if (pending) console.log(`${seconds()}s [${label}] ${pending}`) })
}
child.once('error', error => { console.error(`[${label}] ${error.message}`); resolve({ label, code: 1, at: seconds() }) })
child.once('exit', code => resolve({ label, code: code ?? 1, at: seconds() }))
})
}
const jobs = [run('primary', [], { MCP_INTEGRATION_SKIP: Object.values(shards).flat().join(',') })]
for (const [label, names] of Object.entries(shards)) {
// Stagger starts: each harness picks a free port just before PostgreSQL binds it.
await new Promise(resolve => setTimeout(resolve, 1500))
jobs.push(run(label, [`--acceptance-shard=${names.join(',')}`], {}))
}
const results = await Promise.all(jobs)
console.log('\nMCP PostgreSQL sharded run:')
for (const result of results) console.log(` ${result.code === 0 ? 'PASS' : 'FAIL'} ${result.label} (exit ${result.code}, done at ${result.at.trim()}s)`)
console.log(` total ${seconds().trim()}s`)
process.exitCode = results.every(result => result.code === 0) ? 0 : 1