3 files changed,
+13
−7
internal/edge/tunnel_register_race_test.go
+6 −2
internal/edge/tunnel_upgrade_test.go
+3 −1
internal/edge/upgrades_test.go
+4 −4
| index 771e4fbd6..08e4e03ff 100644 |
| --- a/internal/edge/tunnel_register_race_test.go |
| +++ b/internal/edge/tunnel_register_race_test.go |
| @@ -9,6 +9,7 @@ package edge |
| |
| import ( |
| "bufio" |
| + "io" |
| "net" |
| "net/http" |
| "net/url" |
| @@ -96,13 +97,16 @@ func TestRegistrationRacingARevocationIsNotPublished(t *testing.T) { |
| if err := req.Write(conn); err != nil { |
| t.Fatal(err) |
| } |
| - resp, err := http.ReadResponse(bufio.NewReader(conn), req) |
| + br := bufio.NewReader(conn) |
| + resp, err := http.ReadResponse(br, req) |
| if err != nil || resp.StatusCode != http.StatusSwitchingProtocols { |
| t.Fatalf("registration = %v, %v; want 101", resp, err) |
| } |
| served := make(chan struct{}) |
| go func() { |
| - tunnelclient.ServeWith(conn, namedHandler("box-2"), tunnelclient.DefaultLimits) |
| + // The hub writes the h2 preface straight after the 101, so br may |
| + // already hold it: the box serves what br over-read first. |
| + tunnelclient.ServeWith(&readerConn{Conn: conn, r: io.MultiReader(br, conn)}, namedHandler("box-2"), tunnelclient.DefaultLimits) |
| close(served) |
| }() |
| select { |
| index e741595a5..51343a347 100644 |
| --- a/internal/edge/tunnel_upgrade_test.go |
| +++ b/internal/edge/tunnel_upgrade_test.go |
| @@ -246,7 +246,9 @@ func TestOldBoxKeepsThe502(t *testing.T) { |
| if err != nil || resp.StatusCode != http.StatusSwitchingProtocols { |
| t.Fatalf("registration = %v, %v; want 101", resp, err) |
| } |
| - go tunnelclient.ServeWith(conn, box, tunnelclient.DefaultLimits) |
| + // The hub writes the h2 preface straight after the 101, so br may |
| + // already hold it: the box serves what br over-read first. |
| + go tunnelclient.ServeWith(&readerConn{Conn: conn, r: io.MultiReader(br, conn)}, box, tunnelclient.DefaultLimits) |
| waitForTunnelState(t, hub.tunnels, "away/box-2", "connected", e2eReconnectBound) |
| if tc := hub.tunnels.channel("away/box-2"); tc == nil || tc.caps != "" { |
| t.Fatalf("away/box-2 = %+v, want a channel with no caps", tc) |
| index 1e9b2da67..085780d78 100644 |
| --- a/internal/edge/upgrades_test.go |
| +++ b/internal/edge/upgrades_test.go |
| @@ -451,10 +451,10 @@ func TestRegistrationRecordsCaps(t *testing.T) { |
| if err != nil || resp.StatusCode != http.StatusSwitchingProtocols { |
| t.Fatalf("registration = %v, %v; want 101", resp, err) |
| } |
| - if br.Buffered() != 0 { |
| - t.Fatalf("%d bytes after the 101", br.Buffered()) |
| - } |
| - go tunnelclient.ServeWith(conn, namedHandler("old"), tunnelclient.DefaultLimits) |
| + // No check that br is empty here: the hub writes the h2 preface straight |
| + // after the 101, so the read above may already hold it, depending only on |
| + // timing. The box serves what br over-read first, as tunnelclient.Dial does. |
| + go tunnelclient.ServeWith(&readerConn{Conn: conn, r: io.MultiReader(br, conn)}, namedHandler("old"), tunnelclient.DefaultLimits) |
| waitForTunnelState(t, hub.tunnels, "t1", "connected", e2eReconnectBound) |
| tc := hub.tunnels.channel("t1") |
| if tc == nil || tc.caps != "" { |