sftp/client_integration_test.go

1608 lines
34 KiB
Go
Raw Normal View History

2013-11-06 12:40:35 +08:00
package sftp
// sftp integration tests
// enable with -integration
import (
2013-11-15 18:47:28 +08:00
"crypto/sha1"
2013-11-06 12:40:35 +08:00
"flag"
2013-11-08 19:11:02 +08:00
"io"
2013-11-06 12:40:35 +08:00
"io/ioutil"
"math/rand"
2013-11-06 12:40:35 +08:00
"os"
"os/exec"
"os/user"
2013-11-08 18:00:26 +08:00
"path"
2013-11-08 18:24:50 +08:00
"path/filepath"
"reflect"
"regexp"
"strconv"
2013-11-06 12:40:35 +08:00
"testing"
"testing/quick"
"time"
2013-11-08 18:24:50 +08:00
2013-11-11 09:57:03 +08:00
"github.com/kr/fs"
2013-11-06 12:40:35 +08:00
)
2013-11-06 16:29:59 +08:00
const (
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
READONLY = true
READWRITE = false
NO_DELAY time.Duration = 0
2013-11-08 18:00:26 +08:00
2013-11-08 18:24:50 +08:00
debuglevel = "ERROR" // set to "DEBUG" for debugging
2013-11-06 16:29:59 +08:00
)
var testServerImpl = flag.Bool("testserver", false, "perform integration tests against sftp package server instance")
2013-11-06 12:40:35 +08:00
var testIntegration = flag.Bool("integration", false, "perform integration tests against sftp server process")
var testSftp = flag.String("sftp", sftpServer, "location of the sftp server binary")
2013-11-06 12:40:35 +08:00
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
type delayedWrite struct {
t time.Time
b []byte
}
// delayedWriter wraps a writer and artificially delays the write. This is
// meant to mimic connections with various latencies. Error's returned from the
// underlying writer will panic so this should only be used over reliable
// connections.
type delayedWriter struct {
w io.WriteCloser
ch chan delayedWrite
closed chan struct{}
}
func newDelayedWriter(w io.WriteCloser, delay time.Duration) io.WriteCloser {
ch := make(chan delayedWrite, 128)
closed := make(chan struct{})
go func() {
for writeMsg := range ch {
time.Sleep(writeMsg.t.Add(delay).Sub(time.Now()))
n, err := w.Write(writeMsg.b)
if err != nil {
panic("write error")
}
if n < len(writeMsg.b) {
panic("showrt write")
}
}
w.Close()
close(closed)
}()
return delayedWriter{w: w, ch: ch, closed: closed}
}
func (w delayedWriter) Write(b []byte) (int, error) {
bcopy := make([]byte, len(b))
copy(bcopy, b)
w.ch <- delayedWrite{t: time.Now(), b: bcopy}
return len(b), nil
}
func (w delayedWriter) Close() error {
close(w.ch)
<-w.closed
return nil
}
func testClientGoSvr(t testing.TB, readonly bool, delay time.Duration) (*Client, *exec.Cmd) {
txPipeRd, txPipeWr, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
rxPipeRd, rxPipeWr, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
server, err := NewServer(txPipeRd, rxPipeWr, os.Stderr, 0, readonly, ".")
if err != nil {
t.Fatal(err)
}
go server.Serve()
var ctx io.WriteCloser = txPipeWr
if delay > NO_DELAY {
ctx = newDelayedWriter(ctx, delay)
}
client, err := NewClientPipe(rxPipeRd, ctx)
if err != nil {
t.Fatal(err)
}
// dummy command...
return client, exec.Command("true")
}
2013-11-06 12:40:35 +08:00
// testClient returns a *Client connected to a localy running sftp-server
// the *exec.Cmd returned must be defer Wait'd.
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
func testClient(t testing.TB, readonly bool, delay time.Duration) (*Client, *exec.Cmd) {
2013-11-08 18:00:26 +08:00
if !*testIntegration {
t.Skip("skipping intergration test")
}
if *testServerImpl {
return testClientGoSvr(t, readonly, delay)
}
cmd := exec.Command(*testSftp, "-e", "-R", "-l", debuglevel) // log to stderr, read only
2013-11-06 16:29:59 +08:00
if !readonly {
cmd = exec.Command(*testSftp, "-e", "-l", debuglevel) // log to stderr
2013-11-06 16:29:59 +08:00
}
2013-11-06 12:40:35 +08:00
cmd.Stderr = os.Stdout
pw, err := cmd.StdinPipe()
if err != nil {
t.Fatal(err)
}
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
if delay > NO_DELAY {
pw = newDelayedWriter(pw, delay)
}
2013-11-06 12:40:35 +08:00
pr, err := cmd.StdoutPipe()
if err != nil {
t.Fatal(err)
}
if err := cmd.Start(); err != nil {
t.Skipf("could not start sftp-server process: %v", err)
}
sftp, err := NewClientPipe(pr, pw)
if err != nil {
t.Fatal(err)
2013-11-06 12:40:35 +08:00
}
2013-11-06 12:40:35 +08:00
return sftp, cmd
}
func TestNewClient(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 12:40:35 +08:00
defer cmd.Wait()
if err := sftp.Close(); err != nil {
t.Fatal(err)
}
}
func TestClientLstat(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 12:40:35 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
want, err := os.Lstat(f.Name())
if err != nil {
t.Fatal(err)
}
got, err := sftp.Lstat(f.Name())
if err != nil {
t.Fatal(err)
}
if !sameFile(want, got) {
t.Fatalf("Lstat(%q): want %#v, got %#v", f.Name(), want, got)
}
}
func TestClientLstatIsNotExist(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 16:29:59 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
os.Remove(f.Name())
if _, err := sftp.Lstat(f.Name()); !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) = false, want true", err)
2013-11-06 16:29:59 +08:00
}
}
2014-09-28 10:52:54 +08:00
func TestClientMkdir(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
dir, err := ioutil.TempDir("", "sftptest")
if err != nil {
t.Fatal(err)
}
2014-09-28 10:52:54 +08:00
sub := path.Join(dir, "mkdir1")
if err := sftp.Mkdir(sub); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(sub); err != nil {
t.Fatal(err)
}
2014-09-28 10:52:54 +08:00
}
2013-11-06 12:53:14 +08:00
func TestClientOpen(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 12:53:14 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
got, err := sftp.Open(f.Name())
if err != nil {
t.Fatal(err)
}
if err := got.Close(); err != nil {
t.Fatal(err)
}
}
func TestClientOpenIsNotExist(t *testing.T) {
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
if _, err := sftp.Open("/doesnt/exist/"); !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) = false, want true", err)
}
}
func TestClientStatIsNotExist(t *testing.T) {
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
if _, err := sftp.Stat("/doesnt/exist/"); !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) = false, want true", err)
}
}
const seekBytes = 128 * 1024
type seek struct {
offset int64
}
func (s seek) Generate(r *rand.Rand, _ int) reflect.Value {
s.offset = int64(r.Int31n(seekBytes))
return reflect.ValueOf(s)
}
func (s seek) set(t *testing.T, r io.ReadSeeker) {
if _, err := r.Seek(s.offset, os.SEEK_SET); err != nil {
t.Fatalf("error while seeking with %+v: %v", s, err)
}
}
func (s seek) current(t *testing.T, r io.ReadSeeker) {
const mid = seekBytes / 2
skip := s.offset / 2
if s.offset > mid {
skip = -skip
}
if _, err := r.Seek(mid, os.SEEK_SET); err != nil {
t.Fatalf("error seeking to midpoint with %+v: %v", s, err)
}
if _, err := r.Seek(skip, os.SEEK_CUR); err != nil {
t.Fatalf("error seeking from %d with %+v: %v", mid, s, err)
}
}
func (s seek) end(t *testing.T, r io.ReadSeeker) {
if _, err := r.Seek(-s.offset, os.SEEK_END); err != nil {
t.Fatalf("error seeking from end with %+v: %v", s, err)
}
}
func TestClientSeek(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
fOS, err := ioutil.TempFile("", "seek-test")
if err != nil {
t.Fatal(err)
}
defer fOS.Close()
fSFTP, err := sftp.Open(fOS.Name())
if err != nil {
t.Fatal(err)
}
defer fSFTP.Close()
writeN(t, fOS, seekBytes)
if err := quick.CheckEqual(
func(s seek) (string, int64) { s.set(t, fOS); return readHash(t, fOS) },
func(s seek) (string, int64) { s.set(t, fSFTP); return readHash(t, fSFTP) },
nil,
); err != nil {
t.Errorf("Seek: expected equal absolute seeks: %v", err)
}
if err := quick.CheckEqual(
func(s seek) (string, int64) { s.current(t, fOS); return readHash(t, fOS) },
func(s seek) (string, int64) { s.current(t, fSFTP); return readHash(t, fSFTP) },
nil,
); err != nil {
t.Errorf("Seek: expected equal seeks from middle: %v", err)
}
if err := quick.CheckEqual(
func(s seek) (string, int64) { s.end(t, fOS); return readHash(t, fOS) },
func(s seek) (string, int64) { s.end(t, fSFTP); return readHash(t, fSFTP) },
nil,
); err != nil {
t.Errorf("Seek: expected equal seeks from end: %v", err)
}
2013-11-08 19:11:02 +08:00
}
2013-11-06 16:29:59 +08:00
func TestClientCreate(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
2013-11-06 16:29:59 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer f.Close()
defer os.Remove(f.Name())
f2, err := sftp.Create(f.Name())
if err != nil {
t.Fatal(err)
}
defer f2.Close()
}
2013-11-14 12:32:21 +08:00
func TestClientAppend(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
2013-11-14 12:32:21 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer f.Close()
defer os.Remove(f.Name())
f2, err := sftp.OpenFile(f.Name(), os.O_RDWR|os.O_APPEND)
if err != nil {
t.Fatal(err)
}
defer f2.Close()
}
2013-11-06 16:29:59 +08:00
func TestClientCreateFailed(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 16:29:59 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer f.Close()
defer os.Remove(f.Name())
f2, err := sftp.Create(f.Name())
if err1, ok := err.(*StatusError); !ok || err1.Code != ssh_FX_PERMISSION_DENIED {
t.Fatalf("Create: want: %v, got %#v", ssh_FX_PERMISSION_DENIED, err)
}
if err == nil {
f2.Close()
}
}
2015-09-25 16:05:59 +08:00
func TestClientFileName(t *testing.T) {
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
f2, err := sftp.Open(f.Name())
if err != nil {
t.Fatal(err)
}
if got, want := f2.Name(), f.Name(); got != want {
2015-09-25 16:17:46 +08:00
t.Fatalf("Name: got %q want %q", want, got)
2015-09-25 16:05:59 +08:00
}
}
2013-11-06 13:03:08 +08:00
func TestClientFileStat(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-06 13:03:08 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
want, err := os.Lstat(f.Name())
if err != nil {
t.Fatal(err)
}
f2, err := sftp.Open(f.Name())
if err != nil {
t.Fatal(err)
}
got, err := f2.Stat()
if err != nil {
t.Fatal(err)
}
if !sameFile(want, got) {
t.Fatalf("Lstat(%q): want %#v, got %#v", f.Name(), want, got)
}
}
func TestClientRemove(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Remove(f.Name()); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(f.Name()); !os.IsNotExist(err) {
t.Fatal(err)
}
}
func TestClientRemoveDir(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
dir, err := ioutil.TempDir("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Remove(dir); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(dir); !os.IsNotExist(err) {
t.Fatal(err)
}
}
func TestClientRemoveFailed(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Remove(f.Name()); err == nil {
t.Fatalf("Remove(%v): want: permission denied, got %v", f.Name(), err)
}
if _, err := os.Lstat(f.Name()); err != nil {
t.Fatal(err)
}
}
2013-11-08 19:11:02 +08:00
func TestClientRename(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
2013-11-08 19:11:02 +08:00
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
f2 := f.Name() + ".new"
if err := sftp.Rename(f.Name(), f2); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(f.Name()); !os.IsNotExist(err) {
t.Fatal(err)
}
if _, err := os.Lstat(f2); err != nil {
t.Fatal(err)
}
}
2015-12-22 05:45:40 +08:00
func TestClientGetwd(t *testing.T) {
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
lwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
rwd, err := sftp.Getwd()
if err != nil {
t.Fatal(err)
}
if !path.IsAbs(rwd) {
t.Fatalf("Getwd: wanted absolute path, got %q", rwd)
}
if lwd != rwd {
t.Fatalf("Getwd: want %q, got %q", lwd, rwd)
}
}
2015-08-01 06:46:13 +08:00
func TestClientReadLink(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
f2 := f.Name() + ".sym"
if err := os.Symlink(f.Name(), f2); err != nil {
t.Fatal(err)
}
2015-09-07 16:05:16 +08:00
if rl, err := sftp.ReadLink(f2); err != nil {
t.Fatal(err)
2015-09-07 16:05:16 +08:00
} else if rl != f.Name() {
t.Fatalf("unexpected link target: %v, not %v", rl, f.Name())
}
}
func TestClientSymlink(t *testing.T) {
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
f2 := f.Name() + ".sym"
if err := sftp.Symlink(f.Name(), f2); err != nil {
t.Fatal(err)
}
if rl, err := sftp.ReadLink(f2); err != nil {
t.Fatal(err)
} else if rl != f.Name() {
t.Fatalf("unexpected link target: %v, not %v", rl, f.Name())
}
}
func TestClientChmod(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Chmod(f.Name(), 0531); err != nil {
t.Fatal(err)
}
if stat, err := os.Stat(f.Name()); err != nil {
t.Fatal(err)
} else if stat.Mode()&os.ModePerm != 0531 {
t.Fatalf("invalid perm %o\n", stat.Mode())
}
}
func TestClientChmodReadonly(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Chmod(f.Name(), 0531); err == nil {
t.Fatal("expected error")
}
}
func TestClientChown(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
chownto, err := user.Lookup("daemon") // seems common-ish...
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Log("must be root to run chown tests")
t.Skip()
}
toUid, err := strconv.Atoi(chownto.Uid)
if err != nil {
t.Fatal(err)
}
toGid, err := strconv.Atoi(chownto.Gid)
if err != nil {
t.Fatal(err)
}
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
before, err := exec.Command("ls", "-nl", f.Name()).Output()
if err != nil {
t.Fatal(err)
}
if err := sftp.Chown(f.Name(), toUid, toGid); err != nil {
t.Fatal(err)
}
after, err := exec.Command("ls", "-nl", f.Name()).Output()
if err != nil {
t.Fatal(err)
}
spaceRegex := regexp.MustCompile(`\s+`)
beforeWords := spaceRegex.Split(string(before), -1)
if beforeWords[2] != "0" {
t.Fatalf("bad previous user? should be root")
}
afterWords := spaceRegex.Split(string(after), -1)
if afterWords[2] != chownto.Uid || afterWords[3] != chownto.Gid {
t.Fatalf("bad chown: %#v", afterWords)
}
t.Logf("before: %v", string(before))
t.Logf(" after: %v", string(after))
}
func TestClientChownReadonly(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
chownto, err := user.Lookup("daemon") // seems common-ish...
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Log("must be root to run chown tests")
t.Skip()
}
toUid, err := strconv.Atoi(chownto.Uid)
if err != nil {
t.Fatal(err)
}
toGid, err := strconv.Atoi(chownto.Gid)
if err != nil {
t.Fatal(err)
}
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
if err := sftp.Chown(f.Name(), toUid, toGid); err == nil {
t.Fatal("expected error")
}
}
func TestClientChtimes(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
atime := time.Date(2013, 2, 23, 13, 24, 35, 0, time.UTC)
mtime := time.Date(1985, 6, 12, 6, 6, 6, 0, time.UTC)
if err := sftp.Chtimes(f.Name(), atime, mtime); err != nil {
t.Fatal(err)
}
if stat, err := os.Stat(f.Name()); err != nil {
t.Fatal(err)
} else if stat.ModTime().Sub(mtime) != 0 {
t.Fatalf("incorrect mtime: %v vs %v", stat.ModTime(), mtime)
}
}
func TestClientChtimesReadonly(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
atime := time.Date(2013, 2, 23, 13, 24, 35, 0, time.UTC)
mtime := time.Date(1985, 6, 12, 6, 6, 6, 0, time.UTC)
if err := sftp.Chtimes(f.Name(), atime, mtime); err == nil {
t.Fatal("expected error")
}
}
2015-08-05 13:21:35 +08:00
func TestClientTruncate(t *testing.T) {
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
2015-08-05 13:21:35 +08:00
fname := f.Name()
2015-08-05 13:21:35 +08:00
if n, err := f.Write([]byte("hello world")); n != 11 || err != nil {
t.Fatal(err)
}
f.Close()
if err := sftp.Truncate(fname, 5); err != nil {
t.Fatal(err)
}
if stat, err := os.Stat(fname); err != nil {
t.Fatal(err)
2015-08-05 13:21:35 +08:00
} else if stat.Size() != 5 {
t.Fatalf("unexpected size: %d", stat.Size())
}
}
2015-08-05 13:21:35 +08:00
func TestClientTruncateReadonly(t *testing.T) {
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
t.Fatal(err)
}
fname := f.Name()
if n, err := f.Write([]byte("hello world")); n != 11 || err != nil {
t.Fatal(err)
}
f.Close()
if err := sftp.Truncate(fname, 5); err == nil {
t.Fatal("expected error")
}
if stat, err := os.Stat(fname); err != nil {
t.Fatal(err)
} else if stat.Size() != 11 {
t.Fatalf("unexpected size: %d", stat.Size())
}
}
2013-11-06 12:40:35 +08:00
func sameFile(want, got os.FileInfo) bool {
return want.Name() == got.Name() &&
want.Size() == got.Size()
}
2013-11-08 18:00:26 +08:00
2015-07-30 08:24:24 +08:00
func TestClientReadSimple(t *testing.T) {
2015-08-05 12:11:01 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2015-07-30 08:24:24 +08:00
defer cmd.Wait()
defer sftp.Close()
d, err := ioutil.TempDir("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(d)
f, err := ioutil.TempFile(d, "read-test")
if err != nil {
t.Fatal(err)
}
fname := f.Name()
f.Write([]byte("hello"))
f.Close()
f2, err := sftp.Open(fname)
if err != nil {
t.Fatal(err)
}
defer f2.Close()
stuff := make([]byte, 32)
n, err := f2.Read(stuff)
if err != nil && err != io.EOF {
t.Fatalf("err: %v", err)
}
if n != 5 {
t.Fatalf("n should be 5, is %v", n)
}
if string(stuff[0:5]) != "hello" {
t.Fatalf("invalid contents")
}
}
func TestClientReadDir(t *testing.T) {
sftp1, cmd1 := testClient(t, READONLY, NO_DELAY)
sftp2, cmd2 := testClientGoSvr(t, READONLY, NO_DELAY)
defer cmd1.Wait()
defer cmd2.Wait()
defer sftp1.Close()
defer sftp2.Close()
dir := "/dev/"
d, err := os.Open(dir)
if err != nil {
t.Fatal(err)
}
defer d.Close()
osfiles, err := d.Readdir(4096)
if err != nil {
t.Fatal(err)
}
sftp1Files, err := sftp1.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
sftp2Files, err := sftp2.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
osFilesByName := map[string]os.FileInfo{}
for _, f := range osfiles {
osFilesByName[f.Name()] = f
}
sftp1FilesByName := map[string]os.FileInfo{}
for _, f := range sftp1Files {
sftp1FilesByName[f.Name()] = f
}
sftp2FilesByName := map[string]os.FileInfo{}
for _, f := range sftp2Files {
sftp2FilesByName[f.Name()] = f
}
if len(osFilesByName) != len(sftp1FilesByName) || len(sftp1FilesByName) != len(sftp2FilesByName) {
t.Fatalf("os gives %v, sftp1 gives %v, sftp2 gives %v", len(osFilesByName), len(sftp1FilesByName), len(sftp2FilesByName))
}
for name, osF := range osFilesByName {
sftp1F, ok := sftp1FilesByName[name]
if !ok {
t.Fatalf("%v present in os but not sftp1", name)
}
sftp2F, ok := sftp2FilesByName[name]
if !ok {
t.Fatalf("%v present in os but not sftp2", name)
}
//t.Logf("%v: %v %v %v", name, osF, sftp1F, sftp2F)
if osF.Size() != sftp1F.Size() || sftp1F.Size() != sftp2F.Size() {
t.Fatalf("size %v %v %v", osF.Size(), sftp1F.Size(), sftp2F.Size())
}
if osF.IsDir() != sftp1F.IsDir() || sftp1F.IsDir() != sftp2F.IsDir() {
t.Fatalf("isdir %v %v %v", osF.IsDir(), sftp1F.IsDir(), sftp2F.IsDir())
}
if osF.ModTime().Sub(sftp1F.ModTime()) > time.Second || sftp1F.ModTime() != sftp2F.ModTime() {
t.Fatalf("modtime %v %v %v", osF.ModTime(), sftp1F.ModTime(), sftp2F.ModTime())
}
if osF.Mode() != sftp1F.Mode() || sftp1F.Mode() != sftp2F.Mode() {
t.Fatalf("mode %x %x %x", osF.Mode(), sftp1F.Mode(), sftp2F.Mode())
}
}
}
2013-11-15 18:17:11 +08:00
var clientReadTests = []struct {
n int64
}{
{0},
{1},
{1000},
{1024},
{1025},
{2048},
{4096},
{1 << 12},
{1 << 13},
{1 << 14},
{1 << 15},
{1 << 16},
{1 << 17},
{1 << 18},
{1 << 19},
{1 << 20},
}
func TestClientRead(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-15 18:17:11 +08:00
defer cmd.Wait()
defer sftp.Close()
d, err := ioutil.TempDir("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(d)
for _, tt := range clientReadTests {
f, err := ioutil.TempFile(d, "read-test")
if err != nil {
t.Fatal(err)
}
defer f.Close()
2013-11-15 18:47:28 +08:00
hash := writeN(t, f, tt.n)
2013-11-15 18:17:11 +08:00
f2, err := sftp.Open(f.Name())
if err != nil {
t.Fatal(err)
}
defer f2.Close()
2013-11-15 18:47:28 +08:00
hash2, n := readHash(t, f2)
if hash != hash2 || tt.n != n {
t.Errorf("Read: hash: want: %q, got %q, read: want: %v, got %v", hash, hash2, tt.n, n)
2013-11-15 18:17:11 +08:00
}
}
}
2013-11-15 18:47:28 +08:00
// readHash reads r until EOF returning the number of bytes read
// and the hash of the contents.
func readHash(t *testing.T, r io.Reader) (string, int64) {
h := sha1.New()
tr := io.TeeReader(r, h)
read, err := io.Copy(ioutil.Discard, tr)
if err != nil {
t.Fatal(err)
}
return string(h.Sum(nil)), read
}
// writeN writes n bytes of random data to w and returns the
// hash of that data.
func writeN(t *testing.T, w io.Writer, n int64) string {
rand, err := os.Open("/dev/urandom")
if err != nil {
t.Fatal(err)
}
defer rand.Close()
h := sha1.New()
mw := io.MultiWriter(w, h)
written, err := io.CopyN(mw, rand, n)
if err != nil {
t.Fatal(err)
}
if written != n {
t.Fatalf("CopyN(%v): wrote: %v", n, written)
}
return string(h.Sum(nil))
}
2013-11-08 18:00:26 +08:00
var clientWriteTests = []struct {
n int
total int64 // cumulative file size
}{
{0, 0},
{1, 1},
{0, 1},
{999, 1000},
{24, 1024},
{1023, 2047},
{2048, 4095},
{1 << 12, 8191},
{1 << 13, 16383},
{1 << 14, 32767},
{1 << 15, 65535},
{1 << 16, 131071},
{1 << 17, 262143},
2013-11-08 18:24:50 +08:00
{1 << 18, 524287},
{1 << 19, 1048575},
{1 << 20, 2097151},
{1 << 21, 4194303},
2013-11-08 18:00:26 +08:00
}
func TestClientWrite(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
2013-11-08 18:00:26 +08:00
defer cmd.Wait()
defer sftp.Close()
d, err := ioutil.TempDir("", "sftptest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(d)
f := path.Join(d, "writeTest")
w, err := sftp.Create(f)
if err != nil {
t.Fatal(err)
}
defer w.Close()
for _, tt := range clientWriteTests {
got, err := w.Write(make([]byte, tt.n))
if err != nil {
t.Fatal(err)
}
if got != tt.n {
t.Errorf("Write(%v): wrote: want: %v, got %v", tt.n, tt.n, got)
}
fi, err := os.Stat(f)
if err != nil {
t.Fatal(err)
}
if total := fi.Size(); total != tt.total {
t.Errorf("Write(%v): size: want: %v, got %v", tt.n, tt.total, total)
}
}
}
2013-11-08 18:24:50 +08:00
// taken from github.com/kr/fs/walk_test.go
type PathTest struct {
path, result string
}
type Node struct {
name string
entries []*Node // nil if the entry is a file
mark int
}
var tree = &Node{
"testdata",
[]*Node{
{"a", nil, 0},
{"b", []*Node{}, 0},
{"c", nil, 0},
{
"d",
[]*Node{
{"x", nil, 0},
{"y", []*Node{}, 0},
{
"z",
[]*Node{
{"u", nil, 0},
{"v", nil, 0},
},
0,
},
},
0,
},
},
0,
}
func walkTree(n *Node, path string, f func(path string, n *Node)) {
f(path, n)
for _, e := range n.entries {
walkTree(e, filepath.Join(path, e.name), f)
}
}
func makeTree(t *testing.T) {
walkTree(tree, tree.name, func(path string, n *Node) {
if n.entries == nil {
fd, err := os.Create(path)
if err != nil {
t.Errorf("makeTree: %v", err)
return
}
fd.Close()
} else {
os.Mkdir(path, 0770)
}
})
}
func markTree(n *Node) { walkTree(n, "", func(path string, n *Node) { n.mark++ }) }
func checkMarks(t *testing.T, report bool) {
walkTree(tree, tree.name, func(path string, n *Node) {
if n.mark != 1 && report {
t.Errorf("node %s mark = %d; expected 1", path, n.mark)
}
n.mark = 0
})
}
// Assumes that each node name is unique. Good enough for a test.
// If clear is true, any incoming error is cleared before return. The errors
// are always accumulated, though.
func mark(path string, info os.FileInfo, err error, errors *[]error, clear bool) error {
if err != nil {
*errors = append(*errors, err)
if clear {
return nil
}
return err
}
name := info.Name()
walkTree(tree, tree.name, func(path string, n *Node) {
if n.name == name {
n.mark++
}
})
return nil
}
func TestClientWalk(t *testing.T) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
2013-11-08 18:24:50 +08:00
defer cmd.Wait()
defer sftp.Close()
makeTree(t)
errors := make([]error, 0, 10)
clear := true
markFn := func(walker *fs.Walker) (err error) {
for walker.Step() {
err = mark(walker.Path(), walker.Stat(), walker.Err(), &errors, clear)
if err != nil {
break
}
}
return err
}
// Expect no errors.
err := markFn(sftp.Walk(tree.name))
if err != nil {
t.Fatalf("no error expected, found: %s", err)
}
if len(errors) != 0 {
t.Fatalf("unexpected errors: %s", errors)
}
checkMarks(t, true)
errors = errors[0:0]
// Test permission errors. Only possible if we're not root
// and only on some file systems (AFS, FAT). To avoid errors during
// all.bash on those file systems, skip during go test -short.
if os.Getuid() > 0 && !testing.Short() {
// introduce 2 errors: chmod top-level directories to 0
os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0)
os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0)
// 3) capture errors, expect two.
// mark respective subtrees manually
markTree(tree.entries[1])
markTree(tree.entries[3])
// correct double-marking of directory itself
tree.entries[1].mark--
tree.entries[3].mark--
err := markFn(sftp.Walk(tree.name))
if err != nil {
t.Fatalf("expected no error return from Walk, got %s", err)
}
if len(errors) != 2 {
t.Errorf("expected 2 errors, got %d: %s", len(errors), errors)
}
// the inaccessible subtrees were marked manually
checkMarks(t, true)
errors = errors[0:0]
// 4) capture errors, stop after first error.
// mark respective subtrees manually
markTree(tree.entries[1])
markTree(tree.entries[3])
// correct double-marking of directory itself
tree.entries[1].mark--
tree.entries[3].mark--
clear = false // error will stop processing
err = markFn(sftp.Walk(tree.name))
if err == nil {
t.Fatalf("expected error return from Walk")
}
if len(errors) != 1 {
t.Errorf("expected 1 error, got %d: %s", len(errors), errors)
}
// the inaccessible subtrees were marked manually
checkMarks(t, false)
errors = errors[0:0]
// restore permissions
os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0770)
os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0770)
}
// cleanup
if err := os.RemoveAll(tree.name); err != nil {
t.Errorf("removeTree: %v", err)
}
}
2014-10-09 05:41:54 +08:00
2015-06-15 18:12:08 +08:00
// sftp/issue/42, abrupt server hangup would result in client hangs.
func TestServerRoughDisconnect(t *testing.T) {
if *testServerImpl {
t.Skipf("skipping with -testserver")
}
2015-06-15 18:12:08 +08:00
sftp, cmd := testClient(t, READONLY, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
2015-06-15 18:12:08 +08:00
f, err := sftp.Open("/dev/zero")
if err != nil {
t.Fatal(err)
}
defer f.Close()
go func() {
time.Sleep(100 * time.Millisecond)
cmd.Process.Kill()
}()
io.Copy(ioutil.Discard, f)
}
// sftp/issue/26 writing to a read only file caused client to loop.
func TestClientWriteToROFile(t *testing.T) {
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
defer cmd.Wait()
defer sftp.Close()
f, err := sftp.Open("/dev/zero")
if err != nil {
t.Fatal(err)
}
defer f.Close()
_, err = f.Write([]byte("hello"))
if err == nil {
t.Fatal("expected error, got", err)
}
}
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
func benchmarkRead(b *testing.B, bufsize int, delay time.Duration) {
2014-10-09 05:41:54 +08:00
size := 10*1024*1024 + 123 // ~10MiB
// open sftp client
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(b, READONLY, delay)
2014-10-09 05:41:54 +08:00
defer cmd.Wait()
defer sftp.Close()
buf := make([]byte, bufsize)
b.ResetTimer()
b.SetBytes(int64(size))
for i := 0; i < b.N; i++ {
offset := 0
f2, err := sftp.Open("/dev/zero")
if err != nil {
b.Fatal(err)
}
defer f2.Close()
for offset < size {
n, err := io.ReadFull(f2, buf)
offset += n
if err == io.ErrUnexpectedEOF && offset != size {
b.Fatalf("read too few bytes! want: %d, got: %d", size, n)
}
if err != nil {
b.Fatal(err)
}
offset += n
}
}
}
func BenchmarkRead1k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 1*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead16k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 16*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead32k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 32*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead128k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 128*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead512k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 512*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead1MiB(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 1024*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkRead4MiB(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkRead(b, 4*1024*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
func BenchmarkRead4MiBDelay10Msec(b *testing.B) {
benchmarkRead(b, 4*1024*1024, 10*time.Millisecond)
2014-10-09 05:41:54 +08:00
}
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
func BenchmarkRead4MiBDelay50Msec(b *testing.B) {
benchmarkRead(b, 4*1024*1024, 50*time.Millisecond)
}
func BenchmarkRead4MiBDelay150Msec(b *testing.B) {
benchmarkRead(b, 4*1024*1024, 150*time.Millisecond)
}
func benchmarkWrite(b *testing.B, bufsize int, delay time.Duration) {
2014-10-09 05:41:54 +08:00
size := 10*1024*1024 + 123 // ~10MiB
// open sftp client
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
sftp, cmd := testClient(b, false, delay)
2014-10-09 05:41:54 +08:00
defer cmd.Wait()
defer sftp.Close()
data := make([]byte, size)
b.ResetTimer()
b.SetBytes(int64(size))
for i := 0; i < b.N; i++ {
offset := 0
f, err := ioutil.TempFile("", "sftptest")
if err != nil {
b.Fatal(err)
}
defer os.Remove(f.Name())
f2, err := sftp.Create(f.Name())
if err != nil {
b.Fatal(err)
}
defer f2.Close()
for offset < size {
n, err := f2.Write(data[offset:min(len(data), offset+bufsize)])
if err != nil {
b.Fatal(err)
}
if offset+n < size && n != bufsize {
b.Fatalf("wrote too few bytes! want: %d, got: %d", size, n)
}
offset += n
}
f2.Close()
fi, err := os.Stat(f.Name())
if err != nil {
b.Fatal(err)
}
if fi.Size() != int64(size) {
b.Fatalf("wrong file size: want %d, got %d", size, fi.Size())
}
os.Remove(f.Name())
}
}
func BenchmarkWrite1k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 1*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite16k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 16*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite32k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 32*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite128k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 128*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite512k(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 512*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite1MiB(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 1024*1024, NO_DELAY)
2014-10-09 05:41:54 +08:00
}
func BenchmarkWrite4MiB(b *testing.B) {
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
benchmarkWrite(b, 4*1024*1024, NO_DELAY)
}
func BenchmarkWrite4MiBDelay10Msec(b *testing.B) {
benchmarkWrite(b, 4*1024*1024, 10*time.Millisecond)
}
func BenchmarkWrite4MiBDelay50Msec(b *testing.B) {
benchmarkWrite(b, 4*1024*1024, 50*time.Millisecond)
}
func BenchmarkWrite4MiBDelay150Msec(b *testing.B) {
benchmarkWrite(b, 4*1024*1024, 150*time.Millisecond)
2014-10-09 05:41:54 +08:00
}
Add integration tests that measure how throughput varies with latency. This clearly shows the impact high latency networks have on the throughput of sftp transfers. The current benchmark results on my machine are: $ go test -bench=. -integration PASS BenchmarkRead1k 20 93028268 ns/op 112.72 MB/s BenchmarkRead16k 100 14912438 ns/op 703.16 MB/s BenchmarkRead32k 100 12282661 ns/op 853.71 MB/s BenchmarkRead128k 100 10550935 ns/op 993.83 MB/s BenchmarkRead512k 100 12970518 ns/op 808.44 MB/s BenchmarkRead1MiB 100 11526693 ns/op 909.70 MB/s BenchmarkRead4MiB 100 15761135 ns/op 665.30 MB/s BenchmarkRead4MiBDelay10Msec 1 2662626928 ns/op 3.94 MB/s BenchmarkRead4MiBDelay50Msec 1 12977334971 ns/op 0.81 MB/s BenchmarkRead4MiBDelay150Msec 1 38777294968 ns/op 0.27 MB/s BenchmarkWrite1k 5 235318220 ns/op 44.56 MB/s BenchmarkWrite16k 50 57347520 ns/op 182.85 MB/s BenchmarkWrite32k 30 66151560 ns/op 158.51 MB/s BenchmarkWrite128k 20 86642733 ns/op 121.02 MB/s BenchmarkWrite512k 20 72648883 ns/op 144.34 MB/s BenchmarkWrite1MiB 20 87145317 ns/op 120.33 MB/s BenchmarkWrite4MiB 50 64098344 ns/op 163.59 MB/s BenchmarkWrite4MiBDelay10Msec 1 3360676836 ns/op 3.12 MB/s BenchmarkWrite4MiBDelay50Msec 1 16321294488 ns/op 0.64 MB/s BenchmarkWrite4MiBDelay150Msec 1 48731747397 ns/op 0.22 MB/s BenchmarkCopyDown10MiBDelay10Msec 1 3369680836 ns/op 3.11 MB/s BenchmarkCopyDown10MiBDelay50Msec 1 16228310257 ns/op 0.65 MB/s BenchmarkCopyDown10MiBDelay150Msec 1 48505306499 ns/op 0.22 MB/s BenchmarkCopyUp10MiBDelay10Msec 1 3393474907 ns/op 3.09 MB/s BenchmarkCopyUp10MiBDelay50Msec 1 16273951972 ns/op 0.64 MB/s BenchmarkCopyUp10MiBDelay150Msec 1 48461724780 ns/op 0.22 MB/s BenchmarkMarshalInit 2000000 779 ns/op BenchmarkMarshalOpen 2000000 645 ns/op BenchmarkMarshalWriteWorstCase 20000 70954 ns/op BenchmarkMarshalWrite1k 300000 5072 ns/op ok github.com/pkg/sftp 296.179s
2015-06-03 00:36:35 +08:00
func benchmarkCopyDown(b *testing.B, fileSize int64, delay time.Duration) {
// Create a temp file and fill it with zero's.
src, err := ioutil.TempFile("", "sftptest")
if err != nil {
b.Fatal(err)
}
defer src.Close()
srcFilename := src.Name()
defer os.Remove(srcFilename)
zero, err := os.Open("/dev/zero")
if err != nil {
b.Fatal(err)
}
n, err := io.Copy(src, io.LimitReader(zero, fileSize))
if err != nil {
b.Fatal(err)
}
if n < fileSize {
b.Fatal("short copy")
}
zero.Close()
src.Close()
sftp, cmd := testClient(b, READONLY, delay)
defer cmd.Wait()
defer sftp.Close()
b.ResetTimer()
b.SetBytes(fileSize)
for i := 0; i < b.N; i++ {
dst, err := ioutil.TempFile("", "sftptest")
if err != nil {
b.Fatal(err)
}
defer os.Remove(dst.Name())
src, err := sftp.Open(srcFilename)
if err != nil {
b.Fatal(err)
}
defer src.Close()
n, err := io.Copy(dst, src)
if err != nil {
b.Fatalf("copy error: %v", err)
}
if n < fileSize {
b.Fatal("unable to copy all bytes")
}
dst.Close()
fi, err := os.Stat(dst.Name())
if err != nil {
b.Fatal(err)
}
if fi.Size() != fileSize {
b.Fatalf("wrong file size: want %d, got %d", fileSize, fi.Size())
}
os.Remove(dst.Name())
}
}
func BenchmarkCopyDown10MiBDelay10Msec(b *testing.B) {
benchmarkCopyDown(b, 10*1024*1024, 10*time.Millisecond)
}
func BenchmarkCopyDown10MiBDelay50Msec(b *testing.B) {
benchmarkCopyDown(b, 10*1024*1024, 50*time.Millisecond)
}
func BenchmarkCopyDown10MiBDelay150Msec(b *testing.B) {
benchmarkCopyDown(b, 10*1024*1024, 150*time.Millisecond)
}
func benchmarkCopyUp(b *testing.B, fileSize int64, delay time.Duration) {
// Create a temp file and fill it with zero's.
src, err := ioutil.TempFile("", "sftptest")
if err != nil {
b.Fatal(err)
}
defer src.Close()
srcFilename := src.Name()
defer os.Remove(srcFilename)
zero, err := os.Open("/dev/zero")
if err != nil {
b.Fatal(err)
}
n, err := io.Copy(src, io.LimitReader(zero, fileSize))
if err != nil {
b.Fatal(err)
}
if n < fileSize {
b.Fatal("short copy")
}
zero.Close()
src.Close()
sftp, cmd := testClient(b, false, delay)
defer cmd.Wait()
defer sftp.Close()
b.ResetTimer()
b.SetBytes(fileSize)
for i := 0; i < b.N; i++ {
tmp, err := ioutil.TempFile("", "sftptest")
if err != nil {
b.Fatal(err)
}
tmp.Close()
defer os.Remove(tmp.Name())
dst, err := sftp.Create(tmp.Name())
if err != nil {
b.Fatal(err)
}
defer dst.Close()
src, err := os.Open(srcFilename)
if err != nil {
b.Fatal(err)
}
defer src.Close()
n, err := io.Copy(dst, src)
if err != nil {
b.Fatalf("copy error: %v", err)
}
if n < fileSize {
b.Fatal("unable to copy all bytes")
}
fi, err := os.Stat(tmp.Name())
if err != nil {
b.Fatal(err)
}
if fi.Size() != fileSize {
b.Fatalf("wrong file size: want %d, got %d", fileSize, fi.Size())
}
os.Remove(tmp.Name())
}
}
func BenchmarkCopyUp10MiBDelay10Msec(b *testing.B) {
benchmarkCopyUp(b, 10*1024*1024, 10*time.Millisecond)
}
func BenchmarkCopyUp10MiBDelay50Msec(b *testing.B) {
benchmarkCopyUp(b, 10*1024*1024, 50*time.Millisecond)
}
func BenchmarkCopyUp10MiBDelay150Msec(b *testing.B) {
benchmarkCopyUp(b, 10*1024*1024, 150*time.Millisecond)
2014-10-09 05:41:54 +08:00
}