diff --git a/scripts/ubicloud/pregate-remote.sh b/scripts/ubicloud/pregate-remote.sh index ab47f9ea2..2727b7d00 100755 --- a/scripts/ubicloud/pregate-remote.sh +++ b/scripts/ubicloud/pregate-remote.sh @@ -127,8 +127,9 @@ if [ -z "$outer_s" ]; then for _ in 1 2 3 4 5 6 7 8; do { [ -n "$pid" ] && [ "$pid" -gt 1 ]; } || break cmdline=$(ps -o args= -p "$pid" 2>/dev/null) || break - case $cmdline in - *gstack-pregate*) + read -r arg0 arg1 _ <<<"$cmdline" || true + case "${arg0##*/} ${arg1##*/}" in + "gstack-pregate "*|*" gstack-pregate") outer_s=$(sed -n 's/.*--timeout[ =]\([0-9][0-9]*\).*/\1/p' <<<"$cmdline") outer_s=${outer_s:-600} outer_from="gstack-pregate --timeout" break ;; diff --git a/test/ubicloud-pregate-remote.test.ts b/test/ubicloud-pregate-remote.test.ts index 2a4a66a9c..1cb8820c0 100644 --- a/test/ubicloud-pregate-remote.test.ts +++ b/test/ubicloud-pregate-remote.test.ts @@ -321,14 +321,16 @@ describe('pregate-remote.sh keyed path (stub ubi-runner)', () => { expect(fs.readFileSync(f.calls, 'utf8').trim().split('\n')).toHaveLength(1); // Run under a process named gstack-pregate, the deadline is read from its --timeout (600 s when it passes none). const shim = path.join(path.dirname(f.repo), 'gstack-pregate'); - fs.writeFileSync(shim, '#!/usr/bin/env bash\nexec bash scripts/ubicloud/pregate-remote.sh\n', { mode: 0o755 }); - const run = (args: string[]) => { - const r = Bun.spawnSync(['bash', '-c', '"$0" "$@"; exit $?', shim, ...args], { cwd: f.repo, timeout: 90_000, env: { ...process.env, ...KEY, UBI_SIZE: '', GSTACK_FREE_JOBS: '2', + fs.writeFileSync(shim, '#!/usr/bin/env bash\nbash scripts/ubicloud/pregate-remote.sh\n', { mode: 0o755 }); + const run = (args: string[], via = '"$0" "$@"; exit $?') => { + const r = Bun.spawnSync(['bash', '-c', via, shim, ...args], { cwd: f.repo, timeout: 90_000, env: { ...process.env, ...KEY, UBI_SIZE: '', GSTACK_FREE_JOBS: '2', STUB_CALLS: f.calls, STUB_VM_HOME: f.vm, STUB_BIN: f.bin, PREGATE_FILES_FILE: path.join(path.dirname(f.repo), 'files.txt'), PREGATE_TREE: f.tree, PREGATE_SPEND_CAP_USD: '2' } as Record }); return r.stdout.toString() + r.stderr.toString(); }; expect(run(['--stage', 'tests', '--remote', '--timeout', '1200'])).toMatch(/told to stop after 106[0-5]s \(gstack-pregate --timeout 1200s minus/); expect(run(['--stage', 'tests', '--remote'])).toMatch(/told to stop after 46[0-5]s \(gstack-pregate --timeout 600s minus/); + // An ancestor that only mentions gstack-pregate (a shell line running it beside the gate) is not the enclosing pregate. + expect(run([], ': bin/gstack-pregate --timeout 400; bash scripts/ubicloud/pregate-remote.sh; exit $?')).toContain("told to stop after 2520s (the cap's 45 min wall minus 3 min for teardown)"); }, 120_000); test('the VM environment is bun run test:ubicloud\'s (scripts/ubicloud/test-free.sh), so the two cannot drift', () => {