carlos / platform Public

edge tests: the awake-throttle close is waited for, not raced (asset cache plan 3 fix wave 5)

TestAwakeThrottleClosesAndRefusesUpgrades (main's, plans 4c) wrote to
the upgraded socket straight after CloseAccountUpgrades and expected
the read to fail; the proxy's copy loops end asynchronously, so the
line could still be echoed. It failed CI on 198be9e7 and 1 in 300
runs on main, 5 in 300 here. It now writes and reads until the socket
closes, within 5 s, and a read timeout counts as a failure, not a
close. 300/300 pass; with CloseAccountUpgrades cancelling nothing it
still fails.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 401e884726f5df8c9ad43833cdaca73cc1ecd874 parent 198be9e
1 file changed, +17 −3
  • internal/edge/planthrottle_test.go +17 −3

CI passed — run details

diff --git a/internal/edge/planthrottle_test.go b/internal/edge/planthrottle_test.go
index 1a7b7b457..245416df8 100644
--- a/internal/edge/planthrottle_test.go
+++ b/internal/edge/planthrottle_test.go
@@ -139,9 +139,23 @@ func TestAwakeThrottleClosesAndRefusesUpgrades(t *testing.T) {
if n := s.e.CloseAccountUpgrades("bdk"); n != 1 {
t.Fatalf("CloseAccountUpgrades = %d, want 1", n)
}
- fmt.Fprint(c, "two\n")
- if _, err := br.ReadString('\n'); err == nil {
- t.Fatal("the socket stayed open after the account was awake-throttled")
+ // The close is asynchronous: the proxy's copy loops end when the
+ // cancelled context reaches them, so a line written at once can still be
+ // echoed. Wait (bounded) for the socket to close rather than race it.
+ deadline := time.Now().Add(5 * time.Second)
+ for {
+ c.SetDeadline(time.Now().Add(time.Second))
+ fmt.Fprint(c, "two\n")
+ if _, err := br.ReadString('\n'); err != nil {
+ if ne, ok := err.(net.Error); ok && ne.Timeout() {
+ t.Fatal("the socket neither echoed nor closed after the account was awake-throttled")
+ }
+ break
+ }
+ if time.Now().After(deadline) {
+ t.Fatal("the socket stayed open after the account was awake-throttled")
+ }
+ time.Sleep(10 * time.Millisecond)
}
if _, _, status := openSocket(t, s, ptHost); status != http.StatusTooManyRequests {
t.Fatalf("new upgrade while awake-throttled = %d, want 429", status)