Merge pull request #294 from lucas-clemente/benchmark-test

Fix benchmark tests
This commit is contained in:
Lucas Clemente
2016-08-17 15:48:07 +02:00
committed by GitHub

View File

@@ -23,24 +23,37 @@ import (
type linkedConnection struct { type linkedConnection struct {
other *Session other *Session
c chan []byte
} }
func (c *linkedConnection) write(p []byte) error { func newLinkedConnection(other *Session) *linkedConnection {
packet := getPacketBuffer() c := make(chan []byte, 500)
packet = packet[:len(p)] conn := &linkedConnection{
copy(packet, p) c: c,
other: other,
}
go func() { go func() {
time.Sleep(100 * time.Microsecond) for packet := range c {
r := bytes.NewReader(packet) r := bytes.NewReader(packet)
hdr, err := ParsePublicHeader(r) hdr, err := ParsePublicHeader(r)
if err != nil { if err != nil {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
hdr.Raw = packet[:len(packet)-r.Len()] hdr.Raw = packet[:len(packet)-r.Len()]
conn.other.handlePacket(nil, hdr, packet[len(packet)-r.Len():])
c.other.handlePacket(nil, hdr, packet[len(packet)-r.Len():]) }
}() }()
return conn
}
func (c *linkedConnection) write(p []byte) error {
packet := getPacketBuffer()
packet = packet[:len(p)]
copy(packet, p)
select {
case c.c <- packet:
default:
}
return nil return nil
} }
@@ -63,7 +76,7 @@ func setFlowControlParameters(mgr *handshake.ConnectionParametersManager) {
}) })
} }
var _ = PDescribe("Benchmarks", func() { var _ = Describe("Benchmarks", func() {
for i := range protocol.SupportedVersions { for i := range protocol.SupportedVersions {
version := protocol.SupportedVersions[i] version := protocol.SupportedVersions[i]
@@ -74,14 +87,14 @@ var _ = PDescribe("Benchmarks", func() {
Measure("two linked sessions", func(b Benchmarker) { Measure("two linked sessions", func(b Benchmarker) {
connID := protocol.ConnectionID(mrand.Uint32()) connID := protocol.ConnectionID(mrand.Uint32())
c1 := &linkedConnection{} c1 := newLinkedConnection(nil)
session1I, err := newSession(c1, version, connID, nil, func(*Session, utils.Stream) {}, func(id protocol.ConnectionID) {}) session1I, err := newSession(c1, version, connID, nil, func(*Session, utils.Stream) {}, func(id protocol.ConnectionID) {})
if err != nil { if err != nil {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
session1 := session1I.(*Session) session1 := session1I.(*Session)
c2 := &linkedConnection{other: session1} c2 := newLinkedConnection(session1)
session2I, err := newSession(c2, version, connID, nil, func(*Session, utils.Stream) {}, func(id protocol.ConnectionID) {}) session2I, err := newSession(c2, version, connID, nil, func(*Session, utils.Stream) {}, func(id protocol.ConnectionID) {})
if err != nil { if err != nil {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())