diff --git a/bench_test.go b/bench_test.go index d6b7348..f3cff42 100644 --- a/bench_test.go +++ b/bench_test.go @@ -4,10 +4,15 @@ import ( "io" "io/ioutil" "testing" + "time" ) func BenchmarkPing(b *testing.B) { client, server := testClientServer() + + client.conn = &delayedConn{conn: client.conn, writeDelay: 10 * time.Millisecond} + server.conn = &delayedConn{conn: server.conn, writeDelay: 10 * time.Millisecond} + defer func() { client.Close() server.Close() diff --git a/session_test.go b/session_test.go index 6a6f4fd..3ed73f6 100644 --- a/session_test.go +++ b/session_test.go @@ -52,6 +52,26 @@ func (p *pipeConn) Close() error { return p.writer.Close() } +type delayedConn struct { + conn io.ReadWriteCloser + writeDelay time.Duration +} + +func (c *delayedConn) Read(b []byte) (int, error) { + return c.conn.Read(b) +} + +func (c *delayedConn) Write(b []byte) (int, error) { + if c.writeDelay != 0 { + time.Sleep(c.writeDelay) + } + return c.conn.Write(b) +} + +func (c *delayedConn) Close() error { + return c.conn.Close() +} + func testConn() (io.ReadWriteCloser, io.ReadWriteCloser) { read1, write1 := io.Pipe() read2, write2 := io.Pipe() @@ -87,6 +107,8 @@ func testClientServerConfig(conf *Config) (*Session, *Session) { func TestPing(t *testing.T) { client, server := testClientServer() + client.conn = &delayedConn{conn: client.conn, writeDelay: 10 * time.Millisecond} + server.conn = &delayedConn{conn: server.conn, writeDelay: 10 * time.Millisecond} defer client.Close() defer server.Close()