-
Notifications
You must be signed in to change notification settings - Fork 1
/
options_test.go
50 lines (47 loc) · 1 KB
/
options_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
// Copyright (c) 2019 Meng Huang ([email protected])
// This package is licensed under a MIT license that can be found in the LICENSE file.
package rpc
import (
"github.com/hslam/rpc/examples/codec/json/service"
"sync"
"testing"
"time"
)
func TestOptions(t *testing.T) {
network := "tcp"
addr := ":9999"
codec := "json"
opts := DefaultOptions()
opts.Network = network
opts.Codec = codec
opts.HeaderEncoder = "json"
server := NewServer()
err := server.Register(new(service.Arith))
if err != nil {
t.Error(err)
}
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
server.ListenWithOptions(addr, opts)
}()
time.Sleep(time.Millisecond * 10)
conn, err := DialWithOptions(addr, opts)
if err != nil {
t.Error(err)
}
A := int32(4)
B := int32(8)
req := &service.ArithRequest{A: A, B: B}
var res service.ArithResponse
if err := conn.Call("Arith.Multiply", req, &res); err != nil {
t.Error(err)
}
if res.Pro != A*B {
t.Error(res.Pro)
}
conn.Close()
server.Close()
wg.Wait()
}