Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions repo_tests/push_marker_20260_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,25 @@ def test_contrast_no_wait_means_no_extra_network_call(tmp_path: Path) -> None:
)
_, calls = _hook(tmp_path, body)
assert calls == ""


def _first_attempt_across_a_second_boundary(tmp_path: Path, hook: str) -> str:
"""A slot taken on the first attempt, with the SECONDS clock moved on while taking it (#21225)."""
body = (
f"{hook}\nlog() {{ :; }}\nunset CI AUTOBOT_MACHINE_SLOT_HELD\n"
"machine_slot_take() { SECONDS=$((SECONDS + 5)); return 0; }\n"
f"export AUTOBOT_MACHINE_SLOT_DIR={tmp_path} AUTOBOT_MACHINE_SLOT_LOADAVG={fake_load(tmp_path / 'loadavg')}\n"
"branch_name=issue-1-a; remote_sha=abc; machine_slot_wait\n"
)
done, calls = _hook(tmp_path, body)
assert done.returncode == 0, done.stderr
return calls


def test_a_first_attempt_take_across_a_second_boundary_sets_no_marker(tmp_path: Path) -> None:
assert _first_attempt_across_a_second_boundary(tmp_path, hook_functions()) == ""


def test_contrast_the_clock_comparison_counted_that_take_as_a_wait(tmp_path: Path) -> None:
clock = hook_functions().replace('[ "$waited" = 1 ] || return 0', '[ "$SECONDS" != "$start" ] || return 0')
assert "ref=refs/push-gate/issue-1-a/" in _first_attempt_across_a_second_boundary(tmp_path, clock)
6 changes: 4 additions & 2 deletions tools/git-hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,15 @@ machine_slot_wait() {
[ -z "${CI:-}" ] && [ -z "${AUTOBOT_MACHINE_SLOT_HELD:-}" ] || return 0
command -v flock >/dev/null 2>&1 || { warn "flock is missing: this push did not queue for a machine slot"; return 0; }
local dir="${AUTOBOT_MACHINE_SLOT_DIR:-${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/autobot-machine-slots-$(id -u)}"
local start=$SECONDS next=$SECONDS every="${AUTOBOT_MACHINE_SLOT_REPORT:-60}" why
local start=$SECONDS next=$SECONDS every="${AUTOBOT_MACHINE_SLOT_REPORT:-60}" why waited=0
mkdir -p "$dir"
while :; do
# A slot is taken only while the 1-minute load is under the ceiling.
if machine_slot_load_high; then
why="$MACHINE_SLOT_LOAD_MSG"
elif machine_slot_take "$dir"; then
[ "$SECONDS" != "$start" ] || return 0
# #21225: a wait is an iteration of this loop; SECONDS is an integer clock and also ticks across a first-attempt take.
[ "$waited" = 1 ] || return 0
log "waited $((SECONDS - start))s for a machine slot"
# #20260: the queue has no time limit, so the marker set before it may be about to expire.
[ -z "${branch_name:-}" ] || push_marker_set "$branch_name" "${remote_sha:-$ZERO}"
Expand All @@ -336,6 +337,7 @@ machine_slot_wait() {
log "queued $((SECONDS - start))s: $why"
next=$((SECONDS + every))
fi
waited=1
sleep "${AUTOBOT_MACHINE_SLOT_POLL:-5}"
done
}
Expand Down
Loading