gateway tests: a rest one test records is let go when it ends (#6717)
restingUntil is package-global. Six tests leave a Codex usage-limit rest behind (TestAccountProxy, TestCodexOwnModelMovesToNextAccount, TestCodexSwitchedAccountRestsAsItself, TestCodexPausedOwnAccountPassedOver, TestCodexPoolForwardsCodexHeaders, TestCodexSocketErrorIsItsStatus), and TestEffortChangeKeepsTheCache, whose effortCodexAccount sets its home without fresh(t), started held by it whenever the chunking put them in one process: its first turn was refused in 15ms with "The usage limit has been reached". Red in Race at6e6a18edaand in Test at0dbdc7481. The class, both sides: - fresh(t) clears the rests through noRests() and again when the test ends (t.Cleanup), so a test that comes through fresh leaves none. - noRests() clears restingUntil.lifted too, not only m and note. - The helpers that set a home without fresh (effortCodexAccount, leadSignIn, claudeMadeFirst, piTwoTurns) call noRests first and when they end, as b64Home already did. Run on mote, at6af327e2bplus this change: - Broken by hand: each test of the eleven files whose fakes answer a usage limit, run with TestEffortChangeKeepsTheCache in one process (-test.run '^(T|TestEffortChangeKeepsTheCache)$'). Before: red with the six tests above. After: none red. - internal/gateway plain, sharded as CI does (build/race-shards.sh, 12 workers): 4300 tests, shards_rc=0. - internal/gateway -race, sharded: one red, TestBurstTellsNoSpeed/ responses_from_chat_burst (839ms burst read as 5959 tok/s), a timing red with its issue, #2719 (output recorded there); every other test ok. - gofmt -l internal/gateway: clean. Not run: the other packages (test files of internal/gateway only). Fixes #6717
This commit is contained in:
@@ -28,6 +28,8 @@ func claudeMadeFirst(t *testing.T, bRefuses bool) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("a shell script stands in for Claude Code")
|
||||
}
|
||||
noRests() // a rest an earlier test left must not hold this account (#6717)
|
||||
t.Cleanup(noRests)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
|
||||
@@ -60,6 +60,8 @@ func sentShape(t *testing.T, b []byte) (effort, key string, input []string) {
|
||||
|
||||
func effortCodexAccount(t *testing.T, f *fake) {
|
||||
t.Helper()
|
||||
noRests() // a rest an earlier test left must not hold this account (#6717)
|
||||
t.Cleanup(noRests)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
|
||||
@@ -100,10 +100,14 @@ func setup(t *testing.T, proto provider.Protocol, f *fake) *httptest.Server {
|
||||
}
|
||||
|
||||
// noRests lifts every rest the package's tests have recorded.
|
||||
// noRests clears the package's rests: what rests, why, and what was
|
||||
// lifted. They are package-global, so a rest one test records holds the
|
||||
// next test's account of the same key in the same process (#6717).
|
||||
func noRests() {
|
||||
restingUntil.Lock()
|
||||
restingUntil.m = map[string]time.Time{}
|
||||
restingUntil.note = map[string]Rest{}
|
||||
restingUntil.lifted = map[string]time.Time{}
|
||||
restingUntil.Unlock()
|
||||
codexHolds.Lock()
|
||||
codexHolds.m = nil
|
||||
|
||||
@@ -40,12 +40,10 @@ func fresh(t *testing.T) {
|
||||
t.Setenv("USERPROFILE", home) // Windows finds the home there
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
restingUntil.Lock()
|
||||
restingUntil.m = map[string]time.Time{}
|
||||
restingUntil.Unlock()
|
||||
codexHolds.Lock()
|
||||
codexHolds.m = nil
|
||||
codexHolds.Unlock()
|
||||
// a rest recorded here is let go when the test ends too: the next test
|
||||
// in the process may not come through fresh (#6717)
|
||||
noRests()
|
||||
t.Cleanup(noRests)
|
||||
sticks.Lock()
|
||||
sticks.m = map[string]stick{}
|
||||
sticks.Unlock()
|
||||
|
||||
@@ -31,6 +31,8 @@ func piTwoTurns(t *testing.T, socket bool) {
|
||||
if socket {
|
||||
socketOn(t)
|
||||
}
|
||||
noRests() // a rest an earlier test left must not hold this account (#6717)
|
||||
t.Cleanup(noRests)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
|
||||
@@ -33,6 +33,8 @@ var backendLeads = sse(
|
||||
// backend at f, as the ChatGPT answers come from there.
|
||||
func leadSignIn(t *testing.T, f http.Handler) {
|
||||
t.Helper()
|
||||
noRests() // a rest an earlier test left must not hold this account (#6717)
|
||||
t.Cleanup(noRests)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
|
||||
Reference in New Issue
Block a user