mirror of
https://github.com/golang/go
synced 2024-11-11 23:10:23 -07:00
net: add TestSendfileParts
Add test for freebsd issue #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 #25722 Updates #25809 Change-Id: Ia103bc708b8fa3b9af57613acc44893f90b3fa18 Reviewed-on: https://go-review.googlesource.com/117775 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
b74f7321e5
commit
679690f348
@ -7,11 +7,13 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user