TestCapHoldsUnderParallelSessions went red on ubuntu CI at 93% of a 90%
cap (#6958). Five sessions' turns on one account each checked whether it
was near its cap, and two gaps let a round of them past it:
- A turn found not near was counted out on the account (lanes.out) only
once its try took its lane. Turns checking in between saw none of the
others. Now the check and that count are one step under
nearCaps.check: a turn found not near is counted from its check
(lanes.plan) until its lane counts it, or it leaves. The near path's
wait for turns out (lanes.idle) waits for those too. The key's slot is
taken before the check, as the near path takes it, so a counted turn
never waits for a key slot that a near turn holds while it waits for
the count to drop.
- turnSpends took every turn come back as in the reading when the
reading moved. A reply tells the usage as its turn begins, so the
reading it brings lacks the round out then. At 20 turns come back, the
reading said 82.5% while the account was at 90%. What a turn spent was
halved (7.5 points over 10 turns, not 5), and the 5 turns since were
never ahead of it. lanes.began now notes the turns come back as each
try takes its lane, and ahead counts what that reading has (read).
Turns come back since are ahead of it.
nearChecked is a test hook after the check. TestCapHoldsWithAPauseAfterTheCheck
runs the parallel test with a 15ms pause there, as a busy machine
widens it. TestTurnSpendsAhead gains the case of a round out as the
reading was told.
Run at this change on f9492fd8e:
- mote: go test -race -count=10 -run 'TestCapHolds|TestTurnSpendsAhead|TestLane|Near' ./internal/gateway: ok (31.7s)
- mote: go vet ./internal/gateway: ok
- mote: go test -timeout 45m ./internal/gateway: ok (982.9s)
- mica (mote over its cores then): the cap tests -count=5: ok
Rebased onto f1a4de736 (49e29de7b and 52d527f7b touch the gateway).
At the pushed tree, on mote: the cap, turnSpends, lane and near tests
-count=3 ok; go vet, GOOS=linux and GOOS=windows go vet ./internal/gateway
ok; gofmt -l clean.
Broken by hand, the pause test, 3 runs each:
- On the old code, red 3 of 3: "used 97.5% of a 90% cap after 25
turns; want at most 91.5%".
- With only the read count taken out (ahead given turns as read): red,
93.0%.
- With only the planned count taken out of out and idle: red, 93.0%.
- First cut, with the hook inside the check's lock: green with the
count taken out too, because the lock held the next check for the
pause. The hook now runs after the unlock, where the real gap is.
Not tried: a real Codex account at its cap with parallel sessions. The
reading's turns are those come back at the latest lane take, so a
reading still on its way (lane taken, reply not begun yet) is taken as
having them: a gap of one reply's first byte, not of a whole turn.