mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
test works
This commit is contained in:
parent
e8ef8e1c61
commit
80d48d45d5
1 changed files with 12 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue