forked from andrewarrow/paradise_ftp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
54 lines (46 loc) · 863 Bytes
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import "testing"
import "os"
import "os/exec"
import "paradise/client"
import "math/rand"
import "sync"
import "time"
var file *os.File
var fileBytes []byte
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestSimple(t *testing.T) {
cmd := exec.Command("killall", "paradise")
cmd.Run()
cmd = exec.Command("./paradise")
cmd.Start()
time.Sleep(3 * (time.Second * 1))
testConnect(t)
testLots(t)
}
func testConnect(t *testing.T) {
c := client.NewClient(1)
c.Connect()
c.List()
c.Stor(1024)
}
func testLots(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
for i := 0; i < 5; i++ {
go randClient(i)
time.Sleep((time.Millisecond * 500))
}
wg.Wait()
}
func randClient(id int) {
c := client.NewClient(id)
c.Connect()
for {
c.List()
c.Stor(int64(1024 * 1024 * rand.Intn(20)))
time.Sleep((time.Millisecond * 500))
}
}