Skip to content

Commit

Permalink
net: add TestSendfileParts
Browse files Browse the repository at this point in the history
Add test for freebsd issue golang#25809.

This test also fails on my Windows 10 Version 1803.
My hope is that adding new test will break one of our builders.

Updates golang#25722
Updates golang#25809

Change-Id: Ia103bc708b8fa3b9af57613acc44893f90b3fa18
Reviewed-on: https://go-review.googlesource.com/117775
Run-TryBot: Alex Brainman <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
alexbrainman committed Jun 11, 2018
1 parent b74f732 commit 679690f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/net/sendfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
package net

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
"runtime"
"testing"
)

Expand Down Expand Up @@ -90,3 +92,65 @@ func TestSendfile(t *testing.T) {
t.Error(err)
}
}

func TestSendfileParts(t *testing.T) {
if runtime.GOOS == "freebsd" {
t.Skipf("skipping on %s (see golang.org/issue/25809 for details)", runtime.GOOS)
}

ln, err := newLocalListener("tcp")
if err != nil {
t.Fatal(err)
}
defer ln.Close()

errc := make(chan error, 1)
go func(ln Listener) {
// Wait for a connection.
conn, err := ln.Accept()
if err != nil {
errc <- err
close(errc)
return
}

go func() {
defer close(errc)
defer conn.Close()

f, err := os.Open(twain)
if err != nil {
errc <- err
return
}
defer f.Close()

for i := 0; i < 3; i++ {
// Return file data using io.CopyN, which should use
// sendFile if available.
_, err = io.CopyN(conn, f, 3)
if err != nil {
errc <- err
return
}
}
}()
}(ln)

c, err := Dial("tcp", ln.Addr().String())
if err != nil {
t.Fatal(err)
}
defer c.Close()

buf := new(bytes.Buffer)
buf.ReadFrom(c)

if want, have := "Produced ", buf.String(); have != want {
t.Errorf("unexpected server reply %q, want %q", have, want)
}

for err := range errc {
t.Error(err)
}
}

0 comments on commit 679690f

Please sign in to comment.