MCPcopy Create free account
hub / github.com/CPChain/chain / TestClientBatchRequest

Function TestClientBatchRequest

api/rpc/client_test.go:52–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestClientBatchRequest(t *testing.T) {
53 server := newTestServer("service", new(Service))
54 defer server.Stop()
55 client := DialInProc(server)
56 defer client.Close()
57
58 batch := []BatchElem{
59 {
60 Method: "service_echo",
61 Args: []interface{}{"hello", 10, &Args{"world"}},
62 Result: new(Result),
63 },
64 {
65 Method: "service_echo",
66 Args: []interface{}{"hello2", 11, &Args{"world"}},
67 Result: new(Result),
68 },
69 {
70 Method: "no_such_method",
71 Args: []interface{}{1, 2, 3},
72 Result: new(int),
73 },
74 }
75 if err := client.BatchCall(batch); err != nil {
76 t.Fatal(err)
77 }
78 wantResult := []BatchElem{
79 {
80 Method: "service_echo",
81 Args: []interface{}{"hello", 10, &Args{"world"}},
82 Result: &Result{"hello", 10, &Args{"world"}},
83 },
84 {
85 Method: "service_echo",
86 Args: []interface{}{"hello2", 11, &Args{"world"}},
87 Result: &Result{"hello2", 11, &Args{"world"}},
88 },
89 {
90 Method: "no_such_method",
91 Args: []interface{}{1, 2, 3},
92 Result: new(int),
93 Error: &jsonError{Code: -32601, Message: "The method no_such_method_ does not exist/is not available"},
94 },
95 }
96 if !reflect.DeepEqual(batch, wantResult) {
97 t.Errorf("batch results mismatch:\ngot %swant %s", spew.Sdump(batch), spew.Sdump(wantResult))
98 }
99}
100
101// func TestClientCancelInproc(t *testing.T) { testClientCancel("inproc", t) }
102func TestClientCancelWebsocket(t *testing.T) { testClientCancel("ws", t) }

Callers

nothing calls this directly

Calls 6

newTestServerFunction · 0.85
DialInProcFunction · 0.85
BatchCallMethod · 0.80
StopMethod · 0.65
CloseMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected