Skip to content

Commit b82f062

Browse files
committed
quic: include ignored frames in test log output
When looking at a test log, it's a bit confusing to have some of the frames silently omitted. Print ignored frames. Unfortunately, this means we need to do the actual ignoring of frames after printing the packet. We specify frames to ignore by the frame number, but after parsing we don't have a simple way to map from the debugFrame type back to the number. Add a big, ugly mapping function to do this; it's clunky, but isolated to one function in tests. For golang/go#58547 Change-Id: I242f5511dc16be2350fa49030af38588fe92a988 Reviewed-on: https://go-review.googlesource.com/c/net/+/524295 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 7374d34 commit b82f062

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

internal/quic/conn_test.go

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,80 @@ func (tc *testConn) readDatagram() *testDatagram {
431431
buf := tc.sentDatagrams[0]
432432
tc.sentDatagrams = tc.sentDatagrams[1:]
433433
d := tc.parseTestDatagram(buf)
434+
// Log the datagram before removing ignored frames.
435+
// When things go wrong, it's useful to see all the frames.
434436
tc.logDatagram("-> conn under test sends", d)
437+
typeForFrame := func(f debugFrame) byte {
438+
// This is very clunky, and points at a problem
439+
// in how we specify what frames to ignore in tests.
440+
//
441+
// We mark frames to ignore using the frame type,
442+
// but we've got a debugFrame data structure here.
443+
// Perhaps we should be ignoring frames by debugFrame
444+
// type instead: tc.ignoreFrame[debugFrameAck]().
445+
switch f := f.(type) {
446+
case debugFramePadding:
447+
return frameTypePadding
448+
case debugFramePing:
449+
return frameTypePing
450+
case debugFrameAck:
451+
return frameTypeAck
452+
case debugFrameResetStream:
453+
return frameTypeResetStream
454+
case debugFrameStopSending:
455+
return frameTypeStopSending
456+
case debugFrameCrypto:
457+
return frameTypeCrypto
458+
case debugFrameNewToken:
459+
return frameTypeNewToken
460+
case debugFrameStream:
461+
return frameTypeStreamBase
462+
case debugFrameMaxData:
463+
return frameTypeMaxData
464+
case debugFrameMaxStreamData:
465+
return frameTypeMaxStreamData
466+
case debugFrameMaxStreams:
467+
if f.streamType == bidiStream {
468+
return frameTypeMaxStreamsBidi
469+
} else {
470+
return frameTypeMaxStreamsUni
471+
}
472+
case debugFrameDataBlocked:
473+
return frameTypeDataBlocked
474+
case debugFrameStreamDataBlocked:
475+
return frameTypeStreamDataBlocked
476+
case debugFrameStreamsBlocked:
477+
if f.streamType == bidiStream {
478+
return frameTypeStreamsBlockedBidi
479+
} else {
480+
return frameTypeStreamsBlockedUni
481+
}
482+
case debugFrameNewConnectionID:
483+
return frameTypeNewConnectionID
484+
case debugFrameRetireConnectionID:
485+
return frameTypeRetireConnectionID
486+
case debugFramePathChallenge:
487+
return frameTypePathChallenge
488+
case debugFramePathResponse:
489+
return frameTypePathResponse
490+
case debugFrameConnectionCloseTransport:
491+
return frameTypeConnectionCloseTransport
492+
case debugFrameConnectionCloseApplication:
493+
return frameTypeConnectionCloseApplication
494+
case debugFrameHandshakeDone:
495+
return frameTypeHandshakeDone
496+
}
497+
panic(fmt.Errorf("unhandled frame type %T", f))
498+
}
499+
for _, p := range d.packets {
500+
var frames []debugFrame
501+
for _, f := range p.frames {
502+
if !tc.ignoreFrames[typeForFrame(f)] {
503+
frames = append(frames, f)
504+
}
505+
}
506+
p.frames = frames
507+
}
435508
return d
436509
}
437510

@@ -632,9 +705,7 @@ func (tc *testConn) parseTestFrames(payload []byte) ([]debugFrame, error) {
632705
if n < 0 {
633706
return nil, errors.New("error parsing frames")
634707
}
635-
if !tc.ignoreFrames[payload[0]] {
636-
frames = append(frames, f)
637-
}
708+
frames = append(frames, f)
638709
payload = payload[n:]
639710
}
640711
return frames, nil

0 commit comments

Comments
 (0)