From 80d48d45d58b3234f469cea1564fd7d1e1d47a96 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 24 Sep 2018 07:06:55 -0700 Subject: [PATCH] test works --- src/croc/croc_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index d698d8e..d4dd686 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -2,18 +2,21 @@ package croc import ( "crypto/rand" + "fmt" "io/ioutil" "os" "sync" "testing" "time" + "github.com/schollz/croc/src/utils" "github.com/stretchr/testify/assert" ) func TestSendReceive(t *testing.T) { + var startTime time.Time + var durationPerMegabyte float64 generateRandomFile(100) - var wg sync.WaitGroup wg.Add(2) go func() { @@ -23,13 +26,20 @@ func TestSendReceive(t *testing.T) { }() go func() { defer wg.Done() - time.Sleep(100 * time.Millisecond) + time.Sleep(2 * time.Second) os.MkdirAll("test", 0755) os.Chdir("test") c := Init(true) + startTime = time.Now() assert.Nil(t, c.Receive("test")) + durationPerMegabyte = 100.0 / time.Since(startTime).Seconds() + assert.True(t, utils.Exists("100mb.file")) }() wg.Wait() + os.Chdir("..") + os.RemoveAll("test") + os.Remove("100mb.file") + fmt.Printf("\n-----\n%2.1f MB/s\n----\n", durationPerMegabyte) } func generateRandomFile(megabytes int) {