-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc_test.go
739 lines (592 loc) · 18.7 KB
/
rpc_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
package rpcgo
//go test -race -covermode=atomic -v -coverprofile=coverage.out -run=.
//go tool cover -html=coverage.out
import (
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"net"
"sync"
"testing"
"time"
"github.com/sniperHW/netgo"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
type JsonCodec struct {
}
func (c *JsonCodec) Encode(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
func (c *JsonCodec) Decode(b []byte, v interface{}) error {
return json.Unmarshal(b, v)
}
func init() {
InitLogger(zap.NewExample().Sugar())
}
func AppendByte(bs []byte, v byte) []byte {
return append(bs, v)
}
func AppendBytes(bs []byte, bytes []byte) []byte {
return append(bs, bytes...)
}
func AppendUint32(bs []byte, u32 uint32) []byte {
bu := []byte{0, 0, 0, 0}
binary.BigEndian.PutUint32(bu, u32)
return AppendBytes(bs, bu)
}
const (
packet_msg = byte(1)
packet_rpc_request = byte(2)
packet_rpc_response = byte(3)
)
type testChannel struct {
socket *netgo.AsynSocket
}
func (c *testChannel) RequestWithContext(ctx context.Context, request *RequestMsg) error {
return c.socket.SendWithContext(ctx, request)
}
func (c *testChannel) Request(request *RequestMsg) error {
return c.socket.Send(request, time.Time{})
}
func (c *testChannel) Reply(response *ResponseMsg) error {
return c.socket.Send(response)
}
func (c *testChannel) Name() string {
return fmt.Sprintf("%v <-> %v", c.socket.LocalAddr(), c.socket.RemoteAddr())
}
func (c *testChannel) IsRetryAbleError(_ error) bool {
return false
}
type PacketCodec struct {
r int
w int
buff []byte
}
func (codec *PacketCodec) Decode(b []byte) (interface{}, error) {
switch b[0] {
case packet_rpc_request:
return DecodeRequest(b[1:])
case packet_rpc_response:
return DecodeResponse(b[1:])
case packet_msg:
return string(b[1:]), nil
default:
return nil, errors.New("invaild packet")
}
}
func (codec *PacketCodec) Encode(buffs net.Buffers, o interface{}) (net.Buffers, int) {
var headBytes []byte
var dataBytes []byte
switch o := o.(type) {
case *RequestMsg:
headBytes = AppendUint32(headBytes, 0)
headBytes = AppendByte(headBytes, packet_rpc_request)
dataBytes = EncodeRequest(o)
case *ResponseMsg:
headBytes = AppendUint32(headBytes, 0)
headBytes = AppendByte(headBytes, packet_rpc_response)
dataBytes = EncodeResponse(o)
case string:
headBytes = AppendUint32(headBytes, 0)
headBytes = AppendByte(headBytes, packet_msg)
dataBytes = []byte(o)
default:
return buffs, 0
}
binary.BigEndian.PutUint32(headBytes, uint32(len(dataBytes)+1))
return append(buffs, headBytes, dataBytes), len(dataBytes) + 5
}
func (codec *PacketCodec) read(readable netgo.ReadAble, deadline time.Time) (int, error) {
if err := readable.SetReadDeadline(deadline); err != nil {
return 0, err
} else {
return readable.Read(codec.buff[codec.w:])
}
}
func (codec *PacketCodec) Recv(readable netgo.ReadAble, deadline time.Time) (pkt []byte, err error) {
const lenHead int = 4
for {
rr := codec.r
pktLen := 0
if (codec.w - rr) >= lenHead {
pktLen = int(binary.BigEndian.Uint32(codec.buff[rr:]))
rr += lenHead
}
if pktLen > 0 {
if pktLen > (len(codec.buff) - lenHead) {
err = errors.New("pkt too large")
return
}
if (codec.w - rr) >= pktLen {
pkt = codec.buff[rr : rr+pktLen]
rr += pktLen
codec.r = rr
if codec.r == codec.w {
codec.r = 0
codec.w = 0
}
return
}
}
if codec.r > 0 {
//移动到头部
copy(codec.buff, codec.buff[codec.r:codec.w])
codec.w = codec.w - codec.r
codec.r = 0
}
var n int
n, err = codec.read(readable, deadline)
if n > 0 {
codec.w += n
}
if nil != err {
return
}
}
}
type server struct {
rpcServer *Server
l net.Listener
serve func()
}
func (s *server) start() {
go s.serve()
}
func (s *server) stop() {
s.l.Close()
s.rpcServer.Stop()
}
func newServer(service string) (s *server, err error) {
s = &server{
rpcServer: NewServer(&JsonCodec{}),
}
s.l, s.serve, err = netgo.ListenTCP("tcp", service, func(conn *net.TCPConn) {
logger.Debugf("on new client")
codec := &PacketCodec{buff: make([]byte, 4096)}
as := netgo.NewAsynSocket(netgo.NewTcpSocket(conn, codec),
netgo.AsynSocketOption{
Codec: codec,
AutoRecv: true,
})
as.SetPacketHandler(func(context context.Context, as *netgo.AsynSocket, packet interface{}) error {
switch packet := packet.(type) {
case string:
logger.Debugf("on message")
as.Send(packet)
case *RequestMsg:
s.rpcServer.OnMessage(context, &testChannel{socket: as}, packet)
}
return nil
}).Recv()
})
if err != nil {
return nil, err
} else {
return s, err
}
}
type client struct {
rpcClient *Client
rpcChannel *testChannel
packetHandler func(context context.Context, packet interface{})
}
func newClient(remote string) (*client, error) {
dialer := &net.Dialer{}
conn, err := dialer.Dial("tcp", remote)
if err != nil {
return nil, err
}
codec := &PacketCodec{buff: make([]byte, 4096)}
as := netgo.NewAsynSocket(netgo.NewTcpSocket(conn.(*net.TCPConn), codec),
netgo.AsynSocketOption{
Codec: codec,
AutoRecv: true,
})
rpcChannel := &testChannel{socket: as}
rpcClient := NewClient(&JsonCodec{})
c := &client{
rpcClient: rpcClient,
rpcChannel: rpcChannel,
}
as.SetPacketHandler(func(context context.Context, as *netgo.AsynSocket, packet interface{}) error {
switch packet := packet.(type) {
case *ResponseMsg:
rpcClient.OnMessage(nil, packet)
default:
if c.packetHandler != nil {
c.packetHandler(context, packet)
}
}
return nil
}).Recv()
return c, nil
}
func TestCaller(t *testing.T) {
s, _ := newServer("localhost:8110")
s.rpcServer.SetInInterceptor(append([]func(replyer *Replyer, req *RequestMsg) bool{}, func(replyer *Replyer, req *RequestMsg) bool {
beg := time.Now()
//设置钩子函数,当Replyer发送应答时调用
replyer.AppendOutInterceptor(func(req *RequestMsg, ret interface{}, err error) {
if err == nil {
logger.Debugf("serve %s(\"%v\") resp:%v use:%v", req.Method, *req.GetArg().(*string), ret, time.Now().Sub(beg))
} else {
logger.Debugf("serve %s(\"%v\") with error:%v", req.Method, *req.GetArg().(*string), err)
}
})
return true
}))
s.rpcServer.Register("hello", func(_ context.Context, replyer *Replyer, arg *string) {
replyer.Reply(fmt.Sprintf("hello world:%s", *arg))
})
s.start()
cli, _ := newClient("localhost:8110")
caller := MakeCaller[string, string](cli.rpcClient, "hello", cli.rpcChannel)
caller.Oneway(CallerOpt{}, MakeArgument("Oneway"))
r, err := caller.Call(CallerOpt{Timeout: time.Second}, MakeArgument("CallWithTimeout"))
if err == nil {
fmt.Println(*r, err)
}
c := make(chan struct{})
caller.AsyncCall(CallerOpt{}, MakeArgument("AsyncCall"), func(r *string, err error) {
if err == nil {
fmt.Println(*r, err)
}
close(c)
})
<-c
cli.rpcChannel.socket.Close(nil)
s.stop()
}
func TestAuth(t *testing.T) {
s, _ := newServer("localhost:8110")
s.rpcServer.Register("hello", func(_ context.Context, replyer *Replyer, arg *string) {
replyer.Reply(fmt.Sprintf("hello world:%s", *arg))
})
s.rpcServer.SetInInterceptor(append([]func(replyer *Replyer, req *RequestMsg) bool{}, func(replyer *Replyer, req *RequestMsg) bool {
token := string(req.UserData)
if token == "12345678" {
return true
} else {
replyer.Error(NewError(ErrOther, "auth failed"))
return false
}
}))
s.start()
counter := 0
cli, _ := newClient("localhost:8110")
cli.rpcClient.SetOutInterceptor([]func(*RequestMsg, interface{}){
func(req *RequestMsg, arg interface{}) {
counter++
if counter > 1 {
req.UserData = []byte("87654321")
} else {
req.UserData = []byte("12345678")
}
},
})
var resp string
err := cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Nil(t, err)
assert.Equal(t, resp, "hello world:sniperHW")
err = cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Equal(t, err.Error(), "auth failed")
s.stop()
}
func TestTrace(t *testing.T) {
s, _ := newServer("localhost:8110")
s.rpcServer.Register("hello", func(_ context.Context, replyer *Replyer, arg *string) {
replyer.Reply(fmt.Sprintf("hello world:%s", *arg))
})
s.rpcServer.SetInInterceptor(append([]func(replyer *Replyer, req *RequestMsg) bool{}, func(replyer *Replyer, req *RequestMsg) bool {
traceID := binary.BigEndian.Uint32(req.UserData)
logger.Debugf("[trace] server recv %s traceID:%d", req.Method, traceID)
//设置钩子函数,当Replyer发送应答时调用
replyer.AppendOutInterceptor(func(req *RequestMsg, ret interface{}, err error) {
logger.Debugf("[trace] server reply %s traceID:%d", req.Method, traceID)
})
return true
}))
s.start()
cli, _ := newClient("localhost:8110")
cli.rpcClient.SetOutInterceptor([]func(*RequestMsg, interface{}){
func(req *RequestMsg, arg interface{}) {
//设置traceID
req.UserData = make([]byte, 4)
binary.BigEndian.PutUint32(req.UserData, 1000001)
},
})
cli.rpcClient.SetInInterceptor([]func(*RequestMsg, interface{}, error){
func(req *RequestMsg, ret interface{}, err error) {
traceID := binary.BigEndian.Uint32(req.UserData)
logger.Debugf("%s on response traceID:%d", req.Method, traceID)
},
})
logger.Debugf("begin rpc call")
var resp string
err := cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Nil(t, err)
assert.Equal(t, resp, "hello world:sniperHW")
cli.rpcChannel.socket.Close(nil)
s.stop()
}
func TestRPC(t *testing.T) {
s, _ := newServer("localhost:8110")
s.rpcServer.SetInInterceptor(append([]func(replyer *Replyer, req *RequestMsg) bool{}, func(replyer *Replyer, req *RequestMsg) bool {
beg := time.Now()
//设置钩子函数,当Replyer发送应答时调用
replyer.AppendOutInterceptor(func(req *RequestMsg, ret interface{}, err error) {
if err == nil {
logger.Debugf("serve %s(\"%v\") resp:%v use:%v", req.Method, *req.GetArg().(*string), ret, time.Now().Sub(beg))
} else {
logger.Debugf("serve %s(\"%v\") with error:%v", req.Method, *req.GetArg().(*string), err)
}
})
return true
}))
s.rpcServer.Register("hello", func(_ context.Context, replyer *Replyer, arg *string) {
replyer.Reply(fmt.Sprintf("hello world:%s", *arg))
})
s.rpcServer.Register("timeout", func(_ context.Context, replyer *Replyer, arg *string) {
go func() {
time.Sleep(time.Second * 5)
logger.Debugf("timeout reply")
replyer.Reply(fmt.Sprintf("timeout hello world:%s", *arg))
}()
})
s.start()
cli, _ := newClient("localhost:8110")
msgChan := make(chan struct{})
var pendingCall sync.Map
cli.rpcClient.SetOutInterceptor([]func(*RequestMsg, interface{}){
func(req *RequestMsg, arg interface{}) {
if !req.Oneway {
pendingCall.Store(req.Seq, time.Now())
}
},
})
cli.rpcClient.SetInInterceptor([]func(*RequestMsg, interface{}, error){
func(req *RequestMsg, ret interface{}, err error) {
v, ok := pendingCall.LoadAndDelete(req.Seq)
if ok {
logger.Debugf("call %v(seq:%d,arg:%v,ret:%v,err:%v) use:%v", req.Method, req.Seq, req.GetArg(), ret, err, time.Now().Sub(v.(time.Time)))
}
},
})
cli.packetHandler = func(context context.Context, packet interface{}) {
close(msgChan)
}
cli.rpcChannel.socket.Send("msg")
<-msgChan
logger.Debugf("begin rpc call")
var resp string
err := cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Nil(t, err)
assert.Equal(t, resp, "hello world:sniperHW")
err = cli.rpcClient.AsyncCall(cli.rpcChannel, "hello", "sniperHW", &resp, time.Now().Add(time.Second), func(v interface{}, err error) {
assert.Equal(t, *v.(*string), "hello world:sniperHW")
assert.Nil(t, err)
})
assert.Nil(t, err)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
err = cli.rpcClient.Call(ctx, cli.rpcChannel, "timeout", "sniperHW", &resp)
cancel()
assert.Equal(t, err.(*Error).Is(ErrTimeout), true)
time.Sleep(time.Second)
c := make(chan struct{})
s.rpcServer.Register("syncOneway", func(_ context.Context, replyer *Replyer, arg *string) {
logger.Debugf("syncOneway %s", *arg)
replyer.Reply(*arg)
close(c)
})
err = cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "syncOneway", "sniperHW", nil)
assert.Nil(t, err)
<-c
s.rpcServer.UnRegister("hello")
err = cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Equal(t, err.(*Error).Is(ErrInvaildMethod), true)
s.rpcServer.Register("panic", func(_ context.Context, replyer *Replyer, arg *string) {
//cause panic
panic("panic")
})
err = cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "panic", "sniperHW", &resp)
assert.Equal(t, err.Error(), "method panic")
s.rpcServer.Stop()
err = cli.rpcClient.Call(context.TODO(), cli.rpcChannel, "hello", "sniperHW", &resp)
assert.Equal(t, err.(*Error).Is(ErrServiceUnavaliable), true)
cli.rpcChannel.socket.Close(nil)
s.stop()
}
func TestEnDeCode(t *testing.T) {
{
req := &RequestMsg{
Seq: 10012,
Method: "test",
Arg: []byte("hello"),
Oneway: true,
}
b := EncodeRequest(req)
req = nil
req, _ = DecodeRequest(b)
assert.Equal(t, req.Seq, uint64(10012))
assert.Equal(t, req.Method, "test")
assert.Equal(t, req.Oneway, true)
assert.Equal(t, req.Arg, []byte("hello"))
}
{
req := &RequestMsg{
Seq: 10012,
Method: "test",
Arg: []byte("hello"),
}
b := EncodeRequest(req)
req = nil
req, _ = DecodeRequest(b)
assert.Equal(t, req.Seq, uint64(10012))
assert.Equal(t, req.Method, "test")
assert.Equal(t, req.Oneway, false)
assert.Equal(t, req.Arg, []byte("hello"))
}
{
resp := &ResponseMsg{
Seq: 10012,
Ret: []byte("hello"),
}
b := EncodeResponse(resp)
resp = nil
resp, _ = DecodeResponse(b)
assert.Equal(t, resp.Seq, uint64(10012))
assert.Nil(t, resp.Err)
assert.Equal(t, resp.Ret, []byte("hello"))
}
{
resp := &ResponseMsg{
Seq: 10012,
Ret: []byte("hello"),
Err: NewError(ErrOther, "error"),
}
b := EncodeResponse(resp)
resp = nil
resp, _ = DecodeResponse(b)
assert.Equal(t, resp.Seq, uint64(10012))
assert.Equal(t, resp.Err.Error(), "error")
assert.Equal(t, resp.Ret, []byte("hello"))
}
}
type channelInterestDisconnect struct {
socket *netgo.AsynSocket
pendingCall sync.Map
counter int
}
var errBusy error = errors.New("busy")
func (c *channelInterestDisconnect) RequestWithContext(ctx context.Context, request *RequestMsg) error {
c.counter++
if c.counter < 3 {
return errBusy
}
return c.socket.SendWithContext(ctx, request)
}
func (c *channelInterestDisconnect) Request(request *RequestMsg) error {
c.counter++
if c.counter < 3 {
return errBusy
}
return c.socket.Send(request, time.Time{})
}
func (c *channelInterestDisconnect) Reply(response *ResponseMsg) error {
return c.socket.Send(response)
}
func (c *channelInterestDisconnect) Name() string {
return fmt.Sprintf("%v <-> %v", c.socket.LocalAddr(), c.socket.RemoteAddr())
}
func (c *channelInterestDisconnect) IsRetryAbleError(e error) bool {
return e == errBusy
}
func (c *channelInterestDisconnect) OnDisconnect() {
c.pendingCall.Range(func(key any, value any) bool {
c.pendingCall.Delete(key)
value.(PendingCall).OnDisconnect()
return true
})
}
func (c *channelInterestDisconnect) PutPending(seq uint64, ctx PendingCall) {
c.pendingCall.Store(seq, ctx)
}
func (c *channelInterestDisconnect) LoadAndDeletePending(seq uint64) (interface{}, bool) {
return c.pendingCall.LoadAndDelete(seq)
}
func TestManagePendingChannel(t *testing.T) {
s, _ := newServer("localhost:8110")
s.rpcServer.SetInInterceptor(append([]func(replyer *Replyer, req *RequestMsg) bool{}, func(replyer *Replyer, req *RequestMsg) bool {
beg := time.Now()
//设置钩子函数,当Replyer发送应答时调用
replyer.AppendOutInterceptor(func(req *RequestMsg, ret interface{}, err error) {
if err == nil {
logger.Debugf("serve %s(\"%v\") resp:%v use:%v", req.Method, *req.GetArg().(*string), ret, time.Now().Sub(beg))
} else {
logger.Debugf("serve %s(\"%v\") with error:%v", req.Method, *req.GetArg().(*string), err)
}
})
return true
}))
s.rpcServer.Register("hello", func(_ context.Context, replyer *Replyer, arg *string) {
replyer.Reply(fmt.Sprintf("hello world:%s", *arg))
})
s.rpcServer.Register("timeout", func(_ context.Context, replyer *Replyer, arg *string) {
go func() {
time.Sleep(time.Second * 5)
logger.Debugf("timeout reply")
replyer.Reply(fmt.Sprintf("timeout hello world:%s", *arg))
}()
})
s.start()
dialer := &net.Dialer{}
conn, _ := dialer.Dial("tcp", "localhost:8110")
codec := &PacketCodec{buff: make([]byte, 4096)}
as := netgo.NewAsynSocket(netgo.NewTcpSocket(conn.(*net.TCPConn), codec),
netgo.AsynSocketOption{
Codec: codec,
AutoRecv: true,
})
msgChan := make(chan struct{})
channel := &channelInterestDisconnect{socket: as}
rpcClient := NewClient(&JsonCodec{})
as.SetPacketHandler(func(context context.Context, as *netgo.AsynSocket, packet interface{}) error {
switch packet := packet.(type) {
case string:
close(msgChan)
case *ResponseMsg:
rpcClient.OnMessage(channel, packet)
}
return nil
}).SetCloseCallback(func(_ *netgo.AsynSocket, _ error) {
channel.OnDisconnect()
}).Recv()
as.Send("msg")
<-msgChan
logger.Debugf("begin rpc call")
var resp string
err := rpcClient.Call(context.TODO(), channel, "hello", "sniperHW", &resp)
assert.Nil(t, err)
assert.Equal(t, resp, "hello world:sniperHW")
err = rpcClient.AsyncCall(channel, "hello", "sniperHW", &resp, time.Now().Add(time.Second), func(v interface{}, err error) {
assert.Equal(t, *v.(*string), "hello world:sniperHW")
assert.Nil(t, err)
})
assert.Nil(t, err)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
err = rpcClient.Call(ctx, channel, "timeout", "sniperHW", &resp)
cancel()
assert.Equal(t, err.(*Error).Is(ErrTimeout), true)
go func() {
time.Sleep(time.Second)
as.Close(nil)
}()
ctx, cancel = context.WithTimeout(context.Background(), time.Second*4)
err = rpcClient.Call(ctx, channel, "timeout", "sniperHW", &resp)
cancel()
assert.Equal(t, err.(*Error).Is(ErrDisconnet), true)
s.stop()
}