-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketclient_test.go
More file actions
78 lines (75 loc) · 2.1 KB
/
socketclient_test.go
File metadata and controls
78 lines (75 loc) · 2.1 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package socketclient
import (
"fmt"
// "os"
"testing"
"time"
// "runtime/pprof"
"sync/atomic"
"github.com/stretchr/testify/assert"
)
func TestPC(t *testing.T) {
/*f, err := os.Create("testprof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()*/
PC, err := NewSocketClient("127.0.0.1:8124","test-service")
strt := time.Now()
if assert.NoError(t, err) {
var pong string
err := PC.Exec("ping", "", &pong)
assert.Equal(t, pong, "pong")
assert.Equal(t, err, nil)
for x:= 0; x<10000; x++ {
var test, test2 float64
test = float64(x)
err := PC.Exec("mul10", test, &test2)
//fmt.Printf("%d %#v %#v %#v\n", x, test, test2 , err)
assert.Nil(t, err)
assert.Equal(t, int(test2), int(test*10), "they should be equal")
//assert.NoError(t, err)
//assert.NotNil(t, resp)
}
fmt.Printf("loop end\n")
}
fmt.Printf("%+v\n", time.Since(strt))
PC.Close()
}
func TestPerf(t *testing.T) {
PC, err := NewSocketClient("127.0.0.1:8124","test-service")
assert.NoError(t, err)
cnt := 100
shit := make(chan int)
var doen int64 = 0
strt := time.Now()
for x :=0; x<cnt; x++ {
go func (x int) {
y:=0
for y=0;y<1000; y++ {
var req float64 = float64(y)
var res float64
for {
err := PC.Exec("mul10", req, &res)
if err == ErrReconnect {
fmt.Printf("%d %d Reconnect\n", x, y)
} else {
break
}
}
assert.Nil(t, err)
assert.Equal(t, int(req)*10, int(res))
atomic.AddInt64(&doen,1)
}
shit <- 1
//fmt.Printf("%d %d\n", x, y)
}(x)
}
for z :=0; z<cnt; z++ {
<- shit
}
fmt.Printf("%+v\n", time.Since(strt))
fmt.Printf("Reqdoen: %d\n", doen)
PC.Close()
}