forked from quic-go/quic-go
continuously encode qlog events
This commit is contained in:
@@ -3,6 +3,7 @@ package qlog
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
@@ -23,6 +24,21 @@ func nopWriteCloser(w io.Writer) io.WriteCloser {
|
||||
return &nopWriteCloserImpl{Writer: w}
|
||||
}
|
||||
|
||||
type limitedWriter struct {
|
||||
io.WriteCloser
|
||||
N int
|
||||
written int
|
||||
}
|
||||
|
||||
func (w *limitedWriter) Write(p []byte) (int, error) {
|
||||
if w.written+len(p) > w.N {
|
||||
return 0, errors.New("writer full")
|
||||
}
|
||||
n, err := w.WriteCloser.Write(p)
|
||||
w.written += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
type entry struct {
|
||||
Time time.Time
|
||||
Category string
|
||||
@@ -69,6 +85,18 @@ var _ = Describe("Tracer", func() {
|
||||
Expect(vantagePoint).To(HaveKeyWithValue("type", "server"))
|
||||
})
|
||||
|
||||
It("stops writing when encountering an error", func() {
|
||||
tracer = NewTracer(
|
||||
&limitedWriter{WriteCloser: nopWriteCloser(buf), N: 250},
|
||||
protocol.PerspectiveServer,
|
||||
protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||
)
|
||||
for i := uint32(0); i < 1000; i++ {
|
||||
tracer.UpdatedPTOCount(time.Now(), i)
|
||||
}
|
||||
Expect(tracer.Export()).To(MatchError("writer full"))
|
||||
})
|
||||
|
||||
Context("Events", func() {
|
||||
exportAndParse := func() []entry {
|
||||
Expect(tracer.Export()).To(Succeed())
|
||||
|
||||
Reference in New Issue
Block a user