-
Notifications
You must be signed in to change notification settings - Fork 410
/
erpc_test.go
53 lines (44 loc) · 1.02 KB
/
erpc_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
package erpc_test
import (
"testing"
"time"
"github.com/andeya/erpc/v7"
"github.com/andeya/goutil"
)
func panic_call(erpc.CallCtx, *interface{}) (interface{}, *erpc.Status) {
panic("panic_call")
}
func panic_push(erpc.PushCtx, *interface{}) *erpc.Status {
panic("panic_push")
}
//go:generate go test -v -c -o "${GOPACKAGE}" $GOFILE
func TestPanic(t *testing.T) {
if goutil.IsGoTest() {
t.Log("skip test in go test")
return
}
srv := erpc.NewPeer(erpc.PeerConfig{
CountTime: true,
ListenPort: 9090,
})
srv.RouteCallFunc(panic_call)
srv.RoutePushFunc(panic_push)
go srv.ListenAndServe()
time.Sleep(2 * time.Second)
cli := erpc.NewPeer(erpc.PeerConfig{})
defer cli.Close()
sess, stat := cli.Dial(":9090")
if !stat.OK() {
t.Fatal(stat)
}
stat = sess.Call("/panic/call", nil, nil).Status()
if stat.OK() {
t.Fatalf("/panic/call: expect error!")
}
t.Logf("/panic/call error: %v", stat)
stat = sess.Push("/panic/push", nil)
if !stat.OK() {
t.Fatalf("/panic/push: expect ok!")
}
t.Logf("/panic/push: ok")
}