starpc 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/e2e/mock/mock.pb.d.ts +94 -0
- package/dist/e2e/mock/mock.pb.js +107 -0
- package/dist/echo/echo.pb.d.ts +5 -5
- package/dist/echo/echo.pb.js +21 -21
- package/dist/rpcstream/rpcstream.pb.d.ts +7 -7
- package/dist/rpcstream/rpcstream.pb.js +64 -39
- package/dist/srpc/common-rpc.d.ts +1 -0
- package/dist/srpc/common-rpc.js +19 -4
- package/dist/srpc/rpcproto.pb.d.ts +22 -8
- package/dist/srpc/rpcproto.pb.js +91 -39
- package/e2e/e2e_test.go +65 -15
- package/e2e/mock/mock.go +29 -0
- package/e2e/mock/mock.pb.go +151 -0
- package/e2e/mock/mock.pb.ts +182 -0
- package/e2e/mock/mock.proto +13 -0
- package/e2e/mock/mock_srpc.pb.go +128 -0
- package/e2e/mock/mock_vtproto.pb.go +290 -0
- package/echo/echo.pb.ts +146 -90
- package/go.mod +10 -10
- package/go.sum +20 -20
- package/package.json +3 -3
- package/srpc/client-rpc.go +6 -0
- package/srpc/client.go +3 -0
- package/srpc/common-rpc.ts +21 -4
- package/srpc/msg-stream.go +8 -11
- package/srpc/muxed-conn.go +0 -1
- package/srpc/packet-rw.go +2 -3
- package/srpc/packet.go +7 -0
- package/srpc/rpcproto.pb.go +43 -25
- package/srpc/rpcproto.pb.ts +294 -183
- package/srpc/rpcproto.proto +2 -0
- package/srpc/rpcproto_vtproto.pb.go +74 -0
- package/srpc/server-http.go +1 -1
- package/srpc/server-rpc.go +5 -0
- package/srpc/stream.go +1 -1
- package/srpc/websocket.go +5 -1
- package/srpc/websocket.ts +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import Long from
|
|
2
|
-
import _m0 from
|
|
1
|
+
import Long from 'long';
|
|
2
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
3
3
|
export declare const protobufPackage = "srpc";
|
|
4
4
|
/** Packet is a message sent over a srpc packet connection. */
|
|
5
5
|
export interface Packet {
|
|
6
6
|
body?: {
|
|
7
|
-
$case:
|
|
7
|
+
$case: 'callStart';
|
|
8
8
|
callStart: CallStart;
|
|
9
9
|
} | {
|
|
10
|
-
$case:
|
|
10
|
+
$case: 'callData';
|
|
11
11
|
callData: CallData;
|
|
12
|
+
} | {
|
|
13
|
+
$case: 'callCancel';
|
|
14
|
+
callCancel: boolean;
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
/** CallStart requests starting a new RPC call. */
|
|
@@ -71,6 +74,10 @@ export declare const Packet: {
|
|
|
71
74
|
} | undefined;
|
|
72
75
|
} & {
|
|
73
76
|
$case: "callData";
|
|
77
|
+
}) | ({
|
|
78
|
+
callCancel?: boolean | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
$case: "callCancel";
|
|
74
81
|
}) | undefined;
|
|
75
82
|
} & {
|
|
76
83
|
body?: ({
|
|
@@ -117,8 +124,15 @@ export declare const Packet: {
|
|
|
117
124
|
error?: string | undefined;
|
|
118
125
|
} & { [K_2 in Exclude<keyof I["body"]["callData"], keyof CallData>]: never; }) | undefined;
|
|
119
126
|
$case: "callData";
|
|
120
|
-
} & { [K_3 in Exclude<keyof I["body"], "callData" | "$case">]: never; }) |
|
|
121
|
-
|
|
127
|
+
} & { [K_3 in Exclude<keyof I["body"], "callData" | "$case">]: never; }) | ({
|
|
128
|
+
callCancel?: boolean | undefined;
|
|
129
|
+
} & {
|
|
130
|
+
$case: "callCancel";
|
|
131
|
+
} & {
|
|
132
|
+
callCancel?: boolean | undefined;
|
|
133
|
+
$case: "callCancel";
|
|
134
|
+
} & { [K_4 in Exclude<keyof I["body"], "callCancel" | "$case">]: never; }) | undefined;
|
|
135
|
+
} & { [K_5 in Exclude<keyof I, "body">]: never; }>(object: I): Packet;
|
|
122
136
|
};
|
|
123
137
|
export declare const CallStart: {
|
|
124
138
|
encode(message: CallStart, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -162,9 +176,9 @@ declare type Builtin = Date | Function | Uint8Array | string | number | boolean
|
|
|
162
176
|
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
163
177
|
$case: string;
|
|
164
178
|
} ? {
|
|
165
|
-
[K in keyof Omit<T,
|
|
179
|
+
[K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
|
|
166
180
|
} & {
|
|
167
|
-
$case: T[
|
|
181
|
+
$case: T['$case'];
|
|
168
182
|
} : T extends {} ? {
|
|
169
183
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
170
184
|
} : Partial<T>;
|
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
export const protobufPackage =
|
|
2
|
+
import Long from 'long';
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
4
|
+
export const protobufPackage = 'srpc';
|
|
5
5
|
function createBasePacket() {
|
|
6
6
|
return { body: undefined };
|
|
7
7
|
}
|
|
8
8
|
export const Packet = {
|
|
9
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
-
if (message.body?.$case ===
|
|
10
|
+
if (message.body?.$case === 'callStart') {
|
|
11
11
|
CallStart.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
|
|
12
12
|
}
|
|
13
|
-
if (message.body?.$case ===
|
|
13
|
+
if (message.body?.$case === 'callData') {
|
|
14
14
|
CallData.encode(message.body.callData, writer.uint32(18).fork()).ldelim();
|
|
15
15
|
}
|
|
16
|
+
if (message.body?.$case === 'callCancel') {
|
|
17
|
+
writer.uint32(24).bool(message.body.callCancel);
|
|
18
|
+
}
|
|
16
19
|
return writer;
|
|
17
20
|
},
|
|
18
21
|
decode(input, length) {
|
|
@@ -23,10 +26,19 @@ export const Packet = {
|
|
|
23
26
|
const tag = reader.uint32();
|
|
24
27
|
switch (tag >>> 3) {
|
|
25
28
|
case 1:
|
|
26
|
-
message.body = {
|
|
29
|
+
message.body = {
|
|
30
|
+
$case: 'callStart',
|
|
31
|
+
callStart: CallStart.decode(reader, reader.uint32()),
|
|
32
|
+
};
|
|
27
33
|
break;
|
|
28
34
|
case 2:
|
|
29
|
-
message.body = {
|
|
35
|
+
message.body = {
|
|
36
|
+
$case: 'callData',
|
|
37
|
+
callData: CallData.decode(reader, reader.uint32()),
|
|
38
|
+
};
|
|
39
|
+
break;
|
|
40
|
+
case 3:
|
|
41
|
+
message.body = { $case: 'callCancel', callCancel: reader.bool() };
|
|
30
42
|
break;
|
|
31
43
|
default:
|
|
32
44
|
reader.skipType(tag & 7);
|
|
@@ -66,40 +78,71 @@ export const Packet = {
|
|
|
66
78
|
fromJSON(object) {
|
|
67
79
|
return {
|
|
68
80
|
body: isSet(object.callStart)
|
|
69
|
-
? {
|
|
81
|
+
? {
|
|
82
|
+
$case: 'callStart',
|
|
83
|
+
callStart: CallStart.fromJSON(object.callStart),
|
|
84
|
+
}
|
|
70
85
|
: isSet(object.callData)
|
|
71
|
-
? { $case:
|
|
72
|
-
:
|
|
86
|
+
? { $case: 'callData', callData: CallData.fromJSON(object.callData) }
|
|
87
|
+
: isSet(object.callCancel)
|
|
88
|
+
? { $case: 'callCancel', callCancel: Boolean(object.callCancel) }
|
|
89
|
+
: undefined,
|
|
73
90
|
};
|
|
74
91
|
},
|
|
75
92
|
toJSON(message) {
|
|
76
93
|
const obj = {};
|
|
77
|
-
message.body?.$case ===
|
|
78
|
-
(obj.callStart = message.body?.callStart
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
message.body?.$case === 'callStart' &&
|
|
95
|
+
(obj.callStart = message.body?.callStart
|
|
96
|
+
? CallStart.toJSON(message.body?.callStart)
|
|
97
|
+
: undefined);
|
|
98
|
+
message.body?.$case === 'callData' &&
|
|
99
|
+
(obj.callData = message.body?.callData
|
|
100
|
+
? CallData.toJSON(message.body?.callData)
|
|
101
|
+
: undefined);
|
|
102
|
+
message.body?.$case === 'callCancel' &&
|
|
103
|
+
(obj.callCancel = message.body?.callCancel);
|
|
81
104
|
return obj;
|
|
82
105
|
},
|
|
83
106
|
fromPartial(object) {
|
|
84
107
|
const message = createBasePacket();
|
|
85
|
-
if (object.body?.$case ===
|
|
86
|
-
|
|
108
|
+
if (object.body?.$case === 'callStart' &&
|
|
109
|
+
object.body?.callStart !== undefined &&
|
|
110
|
+
object.body?.callStart !== null) {
|
|
111
|
+
message.body = {
|
|
112
|
+
$case: 'callStart',
|
|
113
|
+
callStart: CallStart.fromPartial(object.body.callStart),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (object.body?.$case === 'callData' &&
|
|
117
|
+
object.body?.callData !== undefined &&
|
|
118
|
+
object.body?.callData !== null) {
|
|
119
|
+
message.body = {
|
|
120
|
+
$case: 'callData',
|
|
121
|
+
callData: CallData.fromPartial(object.body.callData),
|
|
122
|
+
};
|
|
87
123
|
}
|
|
88
|
-
if (object.body?.$case ===
|
|
89
|
-
|
|
124
|
+
if (object.body?.$case === 'callCancel' &&
|
|
125
|
+
object.body?.callCancel !== undefined &&
|
|
126
|
+
object.body?.callCancel !== null) {
|
|
127
|
+
message.body = { $case: 'callCancel', callCancel: object.body.callCancel };
|
|
90
128
|
}
|
|
91
129
|
return message;
|
|
92
130
|
},
|
|
93
131
|
};
|
|
94
132
|
function createBaseCallStart() {
|
|
95
|
-
return {
|
|
133
|
+
return {
|
|
134
|
+
rpcService: '',
|
|
135
|
+
rpcMethod: '',
|
|
136
|
+
data: new Uint8Array(),
|
|
137
|
+
dataIsZero: false,
|
|
138
|
+
};
|
|
96
139
|
}
|
|
97
140
|
export const CallStart = {
|
|
98
141
|
encode(message, writer = _m0.Writer.create()) {
|
|
99
|
-
if (message.rpcService !==
|
|
142
|
+
if (message.rpcService !== '') {
|
|
100
143
|
writer.uint32(10).string(message.rpcService);
|
|
101
144
|
}
|
|
102
|
-
if (message.rpcMethod !==
|
|
145
|
+
if (message.rpcMethod !== '') {
|
|
103
146
|
writer.uint32(18).string(message.rpcMethod);
|
|
104
147
|
}
|
|
105
148
|
if (message.data.length !== 0) {
|
|
@@ -166,9 +209,11 @@ export const CallStart = {
|
|
|
166
209
|
},
|
|
167
210
|
fromJSON(object) {
|
|
168
211
|
return {
|
|
169
|
-
rpcService: isSet(object.rpcService) ? String(object.rpcService) :
|
|
170
|
-
rpcMethod: isSet(object.rpcMethod) ? String(object.rpcMethod) :
|
|
171
|
-
data: isSet(object.data)
|
|
212
|
+
rpcService: isSet(object.rpcService) ? String(object.rpcService) : '',
|
|
213
|
+
rpcMethod: isSet(object.rpcMethod) ? String(object.rpcMethod) : '',
|
|
214
|
+
data: isSet(object.data)
|
|
215
|
+
? bytesFromBase64(object.data)
|
|
216
|
+
: new Uint8Array(),
|
|
172
217
|
dataIsZero: isSet(object.dataIsZero) ? Boolean(object.dataIsZero) : false,
|
|
173
218
|
};
|
|
174
219
|
},
|
|
@@ -183,15 +228,20 @@ export const CallStart = {
|
|
|
183
228
|
},
|
|
184
229
|
fromPartial(object) {
|
|
185
230
|
const message = createBaseCallStart();
|
|
186
|
-
message.rpcService = object.rpcService ??
|
|
187
|
-
message.rpcMethod = object.rpcMethod ??
|
|
231
|
+
message.rpcService = object.rpcService ?? '';
|
|
232
|
+
message.rpcMethod = object.rpcMethod ?? '';
|
|
188
233
|
message.data = object.data ?? new Uint8Array();
|
|
189
234
|
message.dataIsZero = object.dataIsZero ?? false;
|
|
190
235
|
return message;
|
|
191
236
|
},
|
|
192
237
|
};
|
|
193
238
|
function createBaseCallData() {
|
|
194
|
-
return {
|
|
239
|
+
return {
|
|
240
|
+
data: new Uint8Array(),
|
|
241
|
+
dataIsZero: false,
|
|
242
|
+
complete: false,
|
|
243
|
+
error: '',
|
|
244
|
+
};
|
|
195
245
|
}
|
|
196
246
|
export const CallData = {
|
|
197
247
|
encode(message, writer = _m0.Writer.create()) {
|
|
@@ -204,7 +254,7 @@ export const CallData = {
|
|
|
204
254
|
if (message.complete === true) {
|
|
205
255
|
writer.uint32(24).bool(message.complete);
|
|
206
256
|
}
|
|
207
|
-
if (message.error !==
|
|
257
|
+
if (message.error !== '') {
|
|
208
258
|
writer.uint32(34).string(message.error);
|
|
209
259
|
}
|
|
210
260
|
return writer;
|
|
@@ -265,10 +315,12 @@ export const CallData = {
|
|
|
265
315
|
},
|
|
266
316
|
fromJSON(object) {
|
|
267
317
|
return {
|
|
268
|
-
data: isSet(object.data)
|
|
318
|
+
data: isSet(object.data)
|
|
319
|
+
? bytesFromBase64(object.data)
|
|
320
|
+
: new Uint8Array(),
|
|
269
321
|
dataIsZero: isSet(object.dataIsZero) ? Boolean(object.dataIsZero) : false,
|
|
270
322
|
complete: isSet(object.complete) ? Boolean(object.complete) : false,
|
|
271
|
-
error: isSet(object.error) ? String(object.error) :
|
|
323
|
+
error: isSet(object.error) ? String(object.error) : '',
|
|
272
324
|
};
|
|
273
325
|
},
|
|
274
326
|
toJSON(message) {
|
|
@@ -285,28 +337,28 @@ export const CallData = {
|
|
|
285
337
|
message.data = object.data ?? new Uint8Array();
|
|
286
338
|
message.dataIsZero = object.dataIsZero ?? false;
|
|
287
339
|
message.complete = object.complete ?? false;
|
|
288
|
-
message.error = object.error ??
|
|
340
|
+
message.error = object.error ?? '';
|
|
289
341
|
return message;
|
|
290
342
|
},
|
|
291
343
|
};
|
|
292
344
|
var globalThis = (() => {
|
|
293
|
-
if (typeof globalThis !==
|
|
345
|
+
if (typeof globalThis !== 'undefined') {
|
|
294
346
|
return globalThis;
|
|
295
347
|
}
|
|
296
|
-
if (typeof self !==
|
|
348
|
+
if (typeof self !== 'undefined') {
|
|
297
349
|
return self;
|
|
298
350
|
}
|
|
299
|
-
if (typeof window !==
|
|
351
|
+
if (typeof window !== 'undefined') {
|
|
300
352
|
return window;
|
|
301
353
|
}
|
|
302
|
-
if (typeof global !==
|
|
354
|
+
if (typeof global !== 'undefined') {
|
|
303
355
|
return global;
|
|
304
356
|
}
|
|
305
|
-
throw
|
|
357
|
+
throw 'Unable to locate global object';
|
|
306
358
|
})();
|
|
307
359
|
function bytesFromBase64(b64) {
|
|
308
360
|
if (globalThis.Buffer) {
|
|
309
|
-
return Uint8Array.from(globalThis.Buffer.from(b64,
|
|
361
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
|
|
310
362
|
}
|
|
311
363
|
else {
|
|
312
364
|
const bin = globalThis.atob(b64);
|
|
@@ -319,14 +371,14 @@ function bytesFromBase64(b64) {
|
|
|
319
371
|
}
|
|
320
372
|
function base64FromBytes(arr) {
|
|
321
373
|
if (globalThis.Buffer) {
|
|
322
|
-
return globalThis.Buffer.from(arr).toString(
|
|
374
|
+
return globalThis.Buffer.from(arr).toString('base64');
|
|
323
375
|
}
|
|
324
376
|
else {
|
|
325
377
|
const bin = [];
|
|
326
378
|
arr.forEach((byte) => {
|
|
327
379
|
bin.push(String.fromCharCode(byte));
|
|
328
380
|
});
|
|
329
|
-
return globalThis.btoa(bin.join(
|
|
381
|
+
return globalThis.btoa(bin.join(''));
|
|
330
382
|
}
|
|
331
383
|
}
|
|
332
384
|
if (_m0.util.Long !== Long) {
|
package/e2e/e2e_test.go
CHANGED
|
@@ -5,28 +5,37 @@ import (
|
|
|
5
5
|
"io"
|
|
6
6
|
"net"
|
|
7
7
|
"testing"
|
|
8
|
+
"time"
|
|
8
9
|
|
|
10
|
+
e2e_mock "github.com/aperturerobotics/starpc/e2e/mock"
|
|
9
11
|
"github.com/aperturerobotics/starpc/echo"
|
|
10
12
|
"github.com/aperturerobotics/starpc/rpcstream"
|
|
11
13
|
"github.com/aperturerobotics/starpc/srpc"
|
|
12
14
|
"github.com/pkg/errors"
|
|
13
15
|
)
|
|
14
16
|
|
|
17
|
+
const bodyTxt = "hello world via starpc e2e test"
|
|
18
|
+
|
|
15
19
|
// RunE2E runs an end to end test with a callback.
|
|
16
20
|
func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
server := srpc.NewServer(mux)
|
|
21
|
+
RunE2E_Setup(t, func(server *srpc.Server, mux srpc.Mux, client srpc.Client) error {
|
|
22
|
+
// construct the server
|
|
23
|
+
echoServer := echo.NewEchoServer(mux)
|
|
24
|
+
if err := echo.SRPCRegisterEchoer(mux, echoServer); err != nil {
|
|
25
|
+
t.Fatal(err.Error())
|
|
26
|
+
}
|
|
24
27
|
|
|
28
|
+
// construct the client rpc interface
|
|
29
|
+
clientEcho := echo.NewSRPCEchoerClient(client)
|
|
30
|
+
return cb(clientEcho)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// RunE2E_Setup sets up the client and server and calls the callback.
|
|
35
|
+
func RunE2E_Setup(t *testing.T, cb func(server *srpc.Server, mux srpc.Mux, client srpc.Client) error) {
|
|
25
36
|
// Alternatively:
|
|
26
37
|
// openStream := srpc.NewServerPipe(server)
|
|
27
38
|
// client := srpc.NewClient(openStream)
|
|
28
|
-
|
|
29
|
-
// construct the client
|
|
30
39
|
clientPipe, serverPipe := net.Pipe()
|
|
31
40
|
|
|
32
41
|
// outbound=true
|
|
@@ -36,6 +45,9 @@ func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
|
36
45
|
}
|
|
37
46
|
client := srpc.NewClientWithMuxedConn(clientMp)
|
|
38
47
|
|
|
48
|
+
mux := srpc.NewMux()
|
|
49
|
+
server := srpc.NewServer(mux)
|
|
50
|
+
|
|
39
51
|
ctx := context.Background()
|
|
40
52
|
// outbound=false
|
|
41
53
|
serverMp, err := srpc.NewMuxedConn(serverPipe, false, nil)
|
|
@@ -46,11 +58,8 @@ func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
|
46
58
|
_ = server.AcceptMuxedConn(ctx, serverMp)
|
|
47
59
|
}()
|
|
48
60
|
|
|
49
|
-
// construct the client rpc interface
|
|
50
|
-
clientEcho := echo.NewSRPCEchoerClient(client)
|
|
51
|
-
|
|
52
61
|
// call
|
|
53
|
-
if err := cb(
|
|
62
|
+
if err := cb(server, mux, client); err != nil {
|
|
54
63
|
t.Fatal(err.Error())
|
|
55
64
|
}
|
|
56
65
|
}
|
|
@@ -58,7 +67,6 @@ func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
|
58
67
|
func TestE2E_Unary(t *testing.T) {
|
|
59
68
|
ctx := context.Background()
|
|
60
69
|
RunE2E(t, func(client echo.SRPCEchoerClient) error {
|
|
61
|
-
bodyTxt := "hello world"
|
|
62
70
|
out, err := client.Echo(ctx, &echo.EchoMsg{
|
|
63
71
|
Body: bodyTxt,
|
|
64
72
|
})
|
|
@@ -102,7 +110,6 @@ func CheckServerStream(t *testing.T, out echo.SRPCEchoer_EchoServerStreamClient,
|
|
|
102
110
|
func TestE2E_ServerStream(t *testing.T) {
|
|
103
111
|
ctx := context.Background()
|
|
104
112
|
RunE2E(t, func(client echo.SRPCEchoerClient) error {
|
|
105
|
-
bodyTxt := "hello world"
|
|
106
113
|
req := &echo.EchoMsg{
|
|
107
114
|
Body: bodyTxt,
|
|
108
115
|
}
|
|
@@ -114,6 +121,49 @@ func TestE2E_ServerStream(t *testing.T) {
|
|
|
114
121
|
})
|
|
115
122
|
}
|
|
116
123
|
|
|
124
|
+
func TestE2E_Cancel(t *testing.T) {
|
|
125
|
+
rctx := context.Background()
|
|
126
|
+
RunE2E_Setup(t, func(server *srpc.Server, mux srpc.Mux, client srpc.Client) error {
|
|
127
|
+
ctxCh := make(chan context.Context, 1)
|
|
128
|
+
doneCh := make(chan error, 1)
|
|
129
|
+
msrv := &e2e_mock.MockServer{
|
|
130
|
+
MockRequestCb: func(ctx context.Context, msg *e2e_mock.MockMsg) (*e2e_mock.MockMsg, error) {
|
|
131
|
+
ctxCh <- ctx
|
|
132
|
+
<-ctx.Done()
|
|
133
|
+
return nil, context.Canceled
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
_ = msrv.Register(mux)
|
|
137
|
+
|
|
138
|
+
ctx, ctxCancel := context.WithCancel(rctx)
|
|
139
|
+
mclient := e2e_mock.NewSRPCMockClient(client)
|
|
140
|
+
go func() {
|
|
141
|
+
_, err := mclient.MockRequest(ctx, &e2e_mock.MockMsg{Body: bodyTxt})
|
|
142
|
+
doneCh <- err
|
|
143
|
+
}()
|
|
144
|
+
|
|
145
|
+
var reqCtx context.Context
|
|
146
|
+
select {
|
|
147
|
+
case reqCtx = <-ctxCh:
|
|
148
|
+
case <-time.After(time.Millisecond * 100):
|
|
149
|
+
t.FailNow()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
ctxCancel()
|
|
153
|
+
select {
|
|
154
|
+
case <-reqCtx.Done():
|
|
155
|
+
case <-time.After(time.Millisecond * 100):
|
|
156
|
+
t.Fatal("request ctx did not cancel after we canceled client-side ctx")
|
|
157
|
+
}
|
|
158
|
+
select {
|
|
159
|
+
case <-doneCh:
|
|
160
|
+
case <-time.After(time.Millisecond * 100):
|
|
161
|
+
t.Fatal("request did not exit on client side after we canceled ctx")
|
|
162
|
+
}
|
|
163
|
+
return nil
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
117
167
|
// CheckClientStream checks the server stream portion of the Echo test.
|
|
118
168
|
func CheckClientStream(t *testing.T, out echo.SRPCEchoer_EchoClientStreamClient, req *echo.EchoMsg) error {
|
|
119
169
|
// send request
|
package/e2e/mock/mock.go
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package e2e_mock
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
context "context"
|
|
5
|
+
|
|
6
|
+
srpc "github.com/aperturerobotics/starpc/srpc"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// MockServer implements the server for Mock.
|
|
10
|
+
type MockServer struct {
|
|
11
|
+
// MockRequestCb is the callback to implement MockRequest.
|
|
12
|
+
MockRequestCb func(ctx context.Context, msg *MockMsg) (*MockMsg, error)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Register registers the Echo server with the Mux.
|
|
16
|
+
func (e *MockServer) Register(mux srpc.Mux) error {
|
|
17
|
+
return SRPCRegisterMock(mux, e)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// MockRequest implements the mock request rpc.
|
|
21
|
+
func (e *MockServer) MockRequest(ctx context.Context, msg *MockMsg) (*MockMsg, error) {
|
|
22
|
+
if e.MockRequestCb == nil {
|
|
23
|
+
return nil, srpc.ErrUnimplemented
|
|
24
|
+
}
|
|
25
|
+
return e.MockRequestCb(ctx, msg)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// _ is a type assertion
|
|
29
|
+
var _ SRPCMockServer = ((*MockServer)(nil))
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-go v1.28.1-devel
|
|
4
|
+
// protoc v3.19.3
|
|
5
|
+
// source: github.com/aperturerobotics/starpc/e2e/mock/mock.proto
|
|
6
|
+
|
|
7
|
+
package e2e_mock
|
|
8
|
+
|
|
9
|
+
import (
|
|
10
|
+
reflect "reflect"
|
|
11
|
+
sync "sync"
|
|
12
|
+
|
|
13
|
+
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
14
|
+
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const (
|
|
18
|
+
// Verify that this generated code is sufficiently up-to-date.
|
|
19
|
+
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
|
20
|
+
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
21
|
+
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// MockMsg is the mock message body.
|
|
25
|
+
type MockMsg struct {
|
|
26
|
+
state protoimpl.MessageState
|
|
27
|
+
sizeCache protoimpl.SizeCache
|
|
28
|
+
unknownFields protoimpl.UnknownFields
|
|
29
|
+
|
|
30
|
+
Body string `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func (x *MockMsg) Reset() {
|
|
34
|
+
*x = MockMsg{}
|
|
35
|
+
if protoimpl.UnsafeEnabled {
|
|
36
|
+
mi := &file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_msgTypes[0]
|
|
37
|
+
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
38
|
+
ms.StoreMessageInfo(mi)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func (x *MockMsg) String() string {
|
|
43
|
+
return protoimpl.X.MessageStringOf(x)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func (*MockMsg) ProtoMessage() {}
|
|
47
|
+
|
|
48
|
+
func (x *MockMsg) ProtoReflect() protoreflect.Message {
|
|
49
|
+
mi := &file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_msgTypes[0]
|
|
50
|
+
if protoimpl.UnsafeEnabled && x != nil {
|
|
51
|
+
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
52
|
+
if ms.LoadMessageInfo() == nil {
|
|
53
|
+
ms.StoreMessageInfo(mi)
|
|
54
|
+
}
|
|
55
|
+
return ms
|
|
56
|
+
}
|
|
57
|
+
return mi.MessageOf(x)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Deprecated: Use MockMsg.ProtoReflect.Descriptor instead.
|
|
61
|
+
func (*MockMsg) Descriptor() ([]byte, []int) {
|
|
62
|
+
return file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescGZIP(), []int{0}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func (x *MockMsg) GetBody() string {
|
|
66
|
+
if x != nil {
|
|
67
|
+
return x.Body
|
|
68
|
+
}
|
|
69
|
+
return ""
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var File_github_com_aperturerobotics_starpc_e2e_mock_mock_proto protoreflect.FileDescriptor
|
|
73
|
+
|
|
74
|
+
var file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDesc = []byte{
|
|
75
|
+
0x0a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x65,
|
|
76
|
+
0x72, 0x74, 0x75, 0x72, 0x65, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x69, 0x63, 0x73, 0x2f, 0x73, 0x74,
|
|
77
|
+
0x61, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x32, 0x65, 0x2f, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x6d, 0x6f,
|
|
78
|
+
0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x65, 0x32, 0x65, 0x2e, 0x6d, 0x6f,
|
|
79
|
+
0x63, 0x6b, 0x22, 0x1d, 0x0a, 0x07, 0x4d, 0x6f, 0x63, 0x6b, 0x4d, 0x73, 0x67, 0x12, 0x12, 0x0a,
|
|
80
|
+
0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64,
|
|
81
|
+
0x79, 0x32, 0x3b, 0x0a, 0x04, 0x4d, 0x6f, 0x63, 0x6b, 0x12, 0x33, 0x0a, 0x0b, 0x4d, 0x6f, 0x63,
|
|
82
|
+
0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x65, 0x32, 0x65, 0x2e, 0x6d,
|
|
83
|
+
0x6f, 0x63, 0x6b, 0x2e, 0x4d, 0x6f, 0x63, 0x6b, 0x4d, 0x73, 0x67, 0x1a, 0x11, 0x2e, 0x65, 0x32,
|
|
84
|
+
0x65, 0x2e, 0x6d, 0x6f, 0x63, 0x6b, 0x2e, 0x4d, 0x6f, 0x63, 0x6b, 0x4d, 0x73, 0x67, 0x62, 0x06,
|
|
85
|
+
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var (
|
|
89
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescOnce sync.Once
|
|
90
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescData = file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDesc
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
func file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescGZIP() []byte {
|
|
94
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescOnce.Do(func() {
|
|
95
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescData)
|
|
96
|
+
})
|
|
97
|
+
return file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDescData
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
|
101
|
+
var file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_goTypes = []interface{}{
|
|
102
|
+
(*MockMsg)(nil), // 0: e2e.mock.MockMsg
|
|
103
|
+
}
|
|
104
|
+
var file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_depIdxs = []int32{
|
|
105
|
+
0, // 0: e2e.mock.Mock.MockRequest:input_type -> e2e.mock.MockMsg
|
|
106
|
+
0, // 1: e2e.mock.Mock.MockRequest:output_type -> e2e.mock.MockMsg
|
|
107
|
+
1, // [1:2] is the sub-list for method output_type
|
|
108
|
+
0, // [0:1] is the sub-list for method input_type
|
|
109
|
+
0, // [0:0] is the sub-list for extension type_name
|
|
110
|
+
0, // [0:0] is the sub-list for extension extendee
|
|
111
|
+
0, // [0:0] is the sub-list for field type_name
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func init() { file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_init() }
|
|
115
|
+
func file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_init() {
|
|
116
|
+
if File_github_com_aperturerobotics_starpc_e2e_mock_mock_proto != nil {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
if !protoimpl.UnsafeEnabled {
|
|
120
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
|
121
|
+
switch v := v.(*MockMsg); i {
|
|
122
|
+
case 0:
|
|
123
|
+
return &v.state
|
|
124
|
+
case 1:
|
|
125
|
+
return &v.sizeCache
|
|
126
|
+
case 2:
|
|
127
|
+
return &v.unknownFields
|
|
128
|
+
default:
|
|
129
|
+
return nil
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
type x struct{}
|
|
134
|
+
out := protoimpl.TypeBuilder{
|
|
135
|
+
File: protoimpl.DescBuilder{
|
|
136
|
+
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
|
137
|
+
RawDescriptor: file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDesc,
|
|
138
|
+
NumEnums: 0,
|
|
139
|
+
NumMessages: 1,
|
|
140
|
+
NumExtensions: 0,
|
|
141
|
+
NumServices: 1,
|
|
142
|
+
},
|
|
143
|
+
GoTypes: file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_goTypes,
|
|
144
|
+
DependencyIndexes: file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_depIdxs,
|
|
145
|
+
MessageInfos: file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_msgTypes,
|
|
146
|
+
}.Build()
|
|
147
|
+
File_github_com_aperturerobotics_starpc_e2e_mock_mock_proto = out.File
|
|
148
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_rawDesc = nil
|
|
149
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_goTypes = nil
|
|
150
|
+
file_github_com_aperturerobotics_starpc_e2e_mock_mock_proto_depIdxs = nil
|
|
151
|
+
}
|