qlog: disentangle the ConnectionTracer from the qlog writer (#4300)

The qlog writer simply records events, puts them into a channel, and
consumes these events in a separate Go routine (by serializing them).

The ConnectionTracer is the one generating those events.
This commit is contained in:
Marten Seemann
2024-02-02 17:00:15 +07:00
committed by GitHub
parent 0344401de5
commit 225d2a3926
4 changed files with 915 additions and 880 deletions

49
qlog/writer_test.go Normal file
View File

@@ -0,0 +1,49 @@
package qlog
import (
"bytes"
"errors"
"io"
"log"
"os"
"github.com/quic-go/quic-go/internal/protocol"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
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
}
var _ = Describe("Writing", func() {
It("stops writing when encountering an error", func() {
buf := &bytes.Buffer{}
t := NewConnectionTracer(
&limitedWriter{WriteCloser: nopWriteCloser(buf), N: 250},
protocol.PerspectiveServer,
protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
)
for i := uint32(0); i < 1000; i++ {
t.UpdatedPTOCount(i)
}
b := &bytes.Buffer{}
log.SetOutput(b)
defer log.SetOutput(os.Stdout)
t.Close()
Expect(b.String()).To(ContainSubstring("writer full"))
})
})