2018-01-03 19:19:49 +00:00
|
|
|
package wire
|
2017-12-12 02:51:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-01-03 19:19:49 +00:00
|
|
|
"log"
|
2017-12-12 02:51:45 +00:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2018-01-03 19:19:49 +00:00
|
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
|
|
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
2017-12-12 02:51:45 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Frame logging", func() {
|
|
|
|
var (
|
|
|
|
buf bytes.Buffer
|
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
buf.Reset()
|
|
|
|
utils.SetLogLevel(utils.LogLevelDebug)
|
2018-01-03 19:19:49 +00:00
|
|
|
log.SetOutput(&buf)
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterSuite(func() {
|
|
|
|
utils.SetLogLevel(utils.LogLevelNothing)
|
2018-01-03 19:19:49 +00:00
|
|
|
log.SetOutput(os.Stdout)
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("doesn't log when debug is disabled", func() {
|
|
|
|
utils.SetLogLevel(utils.LogLevelInfo)
|
|
|
|
LogFrame(&RstStreamFrame{}, true)
|
|
|
|
Expect(buf.Len()).To(BeZero())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("logs sent frames", func() {
|
|
|
|
LogFrame(&RstStreamFrame{}, true)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("logs received frames", func() {
|
|
|
|
LogFrame(&RstStreamFrame{}, false)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.RstStreamFrame{StreamID:0x0, ErrorCode:0x0, ByteOffset:0x0}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("logs stream frames", func() {
|
|
|
|
frame := &StreamFrame{
|
|
|
|
StreamID: 42,
|
|
|
|
Offset: 0x1337,
|
|
|
|
Data: bytes.Repeat([]byte{'f'}, 0x100),
|
|
|
|
}
|
|
|
|
LogFrame(frame, false)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.StreamFrame{StreamID: 42, FinBit: false, Offset: 0x1337, Data length: 0x100, Offset + Data length: 0x1437}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("logs ACK frames", func() {
|
|
|
|
frame := &AckFrame{
|
|
|
|
LargestAcked: 0x1337,
|
|
|
|
LowestAcked: 0x42,
|
|
|
|
DelayTime: 1 * time.Millisecond,
|
|
|
|
}
|
|
|
|
LogFrame(frame, false)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.AckFrame{LargestAcked: 0x1337, LowestAcked: 0x42, AckRanges: []wire.AckRange(nil), DelayTime: 1ms}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("logs incoming StopWaiting frames", func() {
|
|
|
|
frame := &StopWaitingFrame{
|
|
|
|
LeastUnacked: 0x1337,
|
|
|
|
}
|
|
|
|
LogFrame(frame, false)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.StopWaitingFrame{LeastUnacked: 0x1337}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("logs outgoing StopWaiting frames", func() {
|
|
|
|
frame := &StopWaitingFrame{
|
|
|
|
LeastUnacked: 0x1337,
|
|
|
|
PacketNumberLen: protocol.PacketNumberLen4,
|
|
|
|
}
|
|
|
|
LogFrame(frame, true)
|
2018-01-03 19:19:49 +00:00
|
|
|
Expect(buf.Bytes()).To(ContainSubstring("\t-> &wire.StopWaitingFrame{LeastUnacked: 0x1337, PacketNumberLen: 0x4}\n"))
|
2017-12-12 02:51:45 +00:00
|
|
|
})
|
|
|
|
})
|