|
7 | 7 | package quic
|
8 | 8 |
|
9 | 9 | import (
|
| 10 | + "context" |
10 | 11 | "testing"
|
11 | 12 | )
|
12 | 13 |
|
@@ -36,6 +37,56 @@ func TestConnInflowReturnOnRead(t *testing.T) {
|
36 | 37 | })
|
37 | 38 | }
|
38 | 39 |
|
| 40 | +func TestConnInflowReturnOnRacingReads(t *testing.T) { |
| 41 | + // Perform two reads at the same time, |
| 42 | + // one for half of MaxConnReadBufferSize |
| 43 | + // and one for one byte. |
| 44 | + // |
| 45 | + // We should observe a single MAX_DATA update. |
| 46 | + // Depending on the ordering of events, |
| 47 | + // this may include the credit from just the larger read |
| 48 | + // or the credit from both. |
| 49 | + ctx := canceledContext() |
| 50 | + tc := newTestConn(t, serverSide, func(c *Config) { |
| 51 | + c.MaxConnReadBufferSize = 64 |
| 52 | + }) |
| 53 | + tc.handshake() |
| 54 | + tc.ignoreFrame(frameTypeAck) |
| 55 | + tc.writeFrames(packetType1RTT, debugFrameStream{ |
| 56 | + id: newStreamID(clientSide, uniStream, 0), |
| 57 | + data: make([]byte, 32), |
| 58 | + }) |
| 59 | + tc.writeFrames(packetType1RTT, debugFrameStream{ |
| 60 | + id: newStreamID(clientSide, uniStream, 1), |
| 61 | + data: make([]byte, 32), |
| 62 | + }) |
| 63 | + s1, err := tc.conn.AcceptStream(ctx) |
| 64 | + if err != nil { |
| 65 | + t.Fatalf("conn.AcceptStream() = %v", err) |
| 66 | + } |
| 67 | + s2, err := tc.conn.AcceptStream(ctx) |
| 68 | + if err != nil { |
| 69 | + t.Fatalf("conn.AcceptStream() = %v", err) |
| 70 | + } |
| 71 | + read1 := runAsync(tc, func(ctx context.Context) (int, error) { |
| 72 | + return s1.ReadContext(ctx, make([]byte, 16)) |
| 73 | + }) |
| 74 | + read2 := runAsync(tc, func(ctx context.Context) (int, error) { |
| 75 | + return s2.ReadContext(ctx, make([]byte, 1)) |
| 76 | + }) |
| 77 | + // This MAX_DATA might extend the window by 16 or 17, depending on |
| 78 | + // whether the second write occurs before the update happens. |
| 79 | + tc.wantFrameType("MAX_DATA update is sent", |
| 80 | + packetType1RTT, debugFrameMaxData{}) |
| 81 | + tc.wantIdle("redundant MAX_DATA is not sent") |
| 82 | + if _, err := read1.result(); err != nil { |
| 83 | + t.Errorf("ReadContext #1 = %v", err) |
| 84 | + } |
| 85 | + if _, err := read2.result(); err != nil { |
| 86 | + t.Errorf("ReadContext #2 = %v", err) |
| 87 | + } |
| 88 | +} |
| 89 | + |
39 | 90 | func TestConnInflowReturnOnClose(t *testing.T) {
|
40 | 91 | tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, func(c *Config) {
|
41 | 92 | c.MaxConnReadBufferSize = 64
|
|
0 commit comments