修复 CI:评分点表格前等那一行出现;程序出错时优先报异常;CPU 超时不再生成 core dump
- 评分的"点 / 修改表格单元格"步骤最多等 5 秒,让上一步(保存后重新查询)刷新出的行出现; CI(2 核、整套测试同时跑)上 p6-t2"删除"一项因此偶发失败 - 检查项不通过时,如果程序抛过异常,报"程序出错:…"(异常消息可能比失败的检查晚到) - 学生程序的 CPU 时间上限软硬相同,到时直接 SIGKILL,并且不生成 core dump: 原来先发 SIGXCPU,每个死循环都留下几 MB 的转储,本机桌面还会弹出"程序崩溃" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
670abe5921
commit
a9af26c2d6
2 files changed
+19
-7
No files matched your search
@@ -8,6 +8,8 @@ import type { Check, Expectation, Step } from './checks'
|
||||
import { ProgramDriver } from './driver'
|
||||
|
||||
const GRADE_CONCURRENCY = 6
|
||||
/** 点数据表格的单元格前,最多等多久让那一行出现(程序可能还在查询数据库、刷新表格) */
|
||||
const GRID_WAIT = 5000
|
||||
/** 程序启动后多久内应该显示出窗体 */
|
||||
const START_TIMEOUT = 10_000
|
||||
|
||||
@@ -63,7 +65,11 @@ async function runCheck(dir: string, check: Check, sampleId?: string): Promise<C
|
||||
}
|
||||
return { title: check.title, passed: true }
|
||||
} catch (error) {
|
||||
if (error instanceof Failure) return { title: check.title, passed: false, message: error.message }
|
||||
if (error instanceof Failure) {
|
||||
// 程序抛了异常时,它才是不通过的根本原因(异常消息可能比失败的检查晚到一点)
|
||||
const message = driver.exceptions[0] ? `程序出错:${driver.exceptions[0]}` : error.message
|
||||
return { title: check.title, passed: false, message }
|
||||
}
|
||||
throw error
|
||||
} finally {
|
||||
driver.stop()
|
||||
@@ -111,6 +117,8 @@ async function runStep(driver: ProgramDriver, step: Step) {
|
||||
case 'edit': {
|
||||
const node = need(driver, step.control)
|
||||
if (node.type !== 'DataGridView') throw new Failure(`${step.control} 不是数据表格`)
|
||||
// 上一步(如保存后重新查询)可能还在刷新表格:等这一行出现
|
||||
await driver.waitFor(() => gridRows(need(driver, step.control)).length > step.row, GRID_WAIT)
|
||||
const rows = gridRows(node)
|
||||
if (step.row >= rows.length) throw new Failure(`数据表格 ${step.control} 里没有第 ${step.row + 1} 行(现在有 ${rows.length} 行数据)`)
|
||||
const column = typeof step.column === 'number' ? step.column : gridColumns(node).findIndex((c) => c.header === step.column || c.name === step.column)
|
||||
|
||||
+10
-6
@@ -76,8 +76,9 @@ export function runCommand(projectDir: string, extraEnv: Record<string, string>,
|
||||
const cmd = [
|
||||
// 学生程序写出死循环时,降低它的优先级,网页服务和编译服务仍然流畅
|
||||
'nice', '-n', '10',
|
||||
// CPU 时间用完先收到 SIGXCPU 结束,过几秒还在就强制结束
|
||||
'prlimit', `--cpu=${config.cpuLimitSeconds}:${config.cpuLimitSeconds + 5}`,
|
||||
// CPU 时间用完直接 SIGKILL 结束(软硬上限相同)。软上限更小时内核先发 SIGXCPU,它默认生成 core dump:
|
||||
// 学生每写一次死循环就留下一个转储,本机桌面还会弹出"程序崩溃"
|
||||
'prlimit', `--cpu=${config.cpuLimitSeconds}:${config.cpuLimitSeconds}`, '--core=0',
|
||||
...bwrapArgs(projectDir),
|
||||
...(dbDir ? ['--bind', dbDir, DB_DIR] : []),
|
||||
'dotnet', `${RUNNER_DIR}/${config.runnerDll.split('/').pop()}`, 'run', APP_DIR,
|
||||
@@ -85,12 +86,15 @@ export function runCommand(projectDir: string, extraEnv: Record<string, string>,
|
||||
return { cmd, env }
|
||||
}
|
||||
|
||||
const SIGXCPU = 24
|
||||
const SIGKILL = 9
|
||||
|
||||
/** 运行进程退出时,如果是因为 CPU 时间用完,给学生的说明 */
|
||||
/**
|
||||
* 运行进程退出时,如果是因为 CPU 时间用完,给学生的说明。
|
||||
* CPU 上限到时内核发 SIGKILL,bwrap 把子进程"被信号结束"转成退出码 128 + 信号编号;
|
||||
* 平台自己结束程序(停止、超时、关闭页面)用的是 SIGTERM,不会误报。
|
||||
*/
|
||||
export function cpuLimitMessage(code: number | null, signal: string | number | null) {
|
||||
// bwrap 把子进程"被信号结束"转成退出码 128 + 信号编号
|
||||
return signal === 'SIGXCPU' || code === 128 + SIGXCPU
|
||||
return signal === 'SIGKILL' || code === 128 + SIGKILL
|
||||
? `\n程序占用 CPU 太多,已被结束(累计超过 ${config.cpuLimitSeconds} 秒)。检查是否有死循环:循环里要有退出条件,等待请用 Timer 或 Thread.Sleep。\n`
|
||||
: undefined
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user