-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcliSession_test.go
60 lines (53 loc) · 1018 Bytes
/
cliSession_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
55
56
57
58
59
60
package cliSession_test
import (
"testing"
"time"
tp "github.com/henrylee2cn/teleport"
cliSession "github.com/henrylee2cn/tp-ext/mod-cliSession"
)
type Arg struct {
A int
B int `param:"<range:1:>"`
}
type P struct{ tp.PullCtx }
func (p *P) Divide(arg *Arg) (int, *tp.Rerror) {
return arg.A / arg.B, nil
}
func TestCliSession(t *testing.T) {
srv := tp.NewPeer(tp.PeerConfig{
ListenPort: 9090,
})
srv.RoutePull(new(P))
go srv.ListenAndServe()
time.Sleep(time.Second)
cli := cliSession.New(
tp.NewPeer(tp.PeerConfig{}),
":9090",
100,
time.Second*5,
)
go func() {
for {
t.Logf("%+v", cli.Stats())
time.Sleep(time.Millisecond * 500)
}
}()
go func() {
var result int
for i := 0; ; i++ {
rerr := cli.Pull("/p/divide", &Arg{
A: i,
B: 2,
}, &result).Rerror()
if rerr != nil {
t.Log(rerr)
} else {
t.Logf("%d/2=%v", i, result)
}
time.Sleep(time.Millisecond * 500)
}
}()
time.Sleep(time.Second * 6)
cli.Close()
time.Sleep(time.Second * 3)
}