Skip to content

Commit 08314a9

Browse files
committed
grpc-js-core: fixes for interop test
1 parent d142e1a commit 08314a9

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

packages/grpc-js-core/src/call-credentials.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ComposedCallCredentials implements CallCredentials {
4646
class SingleCallCredentials implements CallCredentials {
4747
constructor(private metadataGenerator: CallMetadataGenerator) {}
4848

49-
async generateMetadata(options: {}): Promise<Metadata> {
49+
generateMetadata(options: {}): Promise<Metadata> {
5050
return new Promise<Metadata>((resolve, reject) => {
5151
this.metadataGenerator(options, (err, metadata) => {
5252
if (metadata !== undefined) {
@@ -64,8 +64,8 @@ class SingleCallCredentials implements CallCredentials {
6464
}
6565

6666
class EmptyCallCredentials implements CallCredentials {
67-
async generateMetadata(options: {}): Promise<Metadata> {
68-
return new Metadata();
67+
generateMetadata(options: {}): Promise<Metadata> {
68+
return Promise.resolve(new Metadata());
6969
}
7070

7171
compose(other: CallCredentials): CallCredentials {

packages/grpc-js-core/src/call-stream.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ export class Http2CallStream extends Duplex implements CallStream {
282282
let code: Status;
283283
let details = '';
284284
switch (errorCode) {
285+
case http2.constants.NGHTTP2_NO_ERROR:
286+
code = Status.OK;
287+
break;
285288
case http2.constants.NGHTTP2_REFUSED_STREAM:
286289
code = Status.UNAVAILABLE;
287290
break;

packages/grpc-js-core/src/call.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export interface Call extends EventEmitter {
3838
event: 'metadata', listener: (metadata: Metadata) => void): this;
3939
removeListener(event: 'metadata', listener: (metadata: Metadata) => void):
4040
this;
41+
42+
addListener(event: 'status', listener: (status: StatusObject) => void): this;
43+
emit(event: 'status', status: StatusObject): boolean;
44+
on(event: 'status', listener: (status: StatusObject) => void): this;
45+
once(event: 'status', listener: (status: StatusObject) => void): this;
46+
prependListener(event: 'status', listener: (status: StatusObject) => void):
47+
this;
48+
prependOnceListener(
49+
event: 'status', listener: (status: StatusObject) => void): this;
50+
removeListener(event: 'status', listener: (status: StatusObject) => void):
51+
this;
4152
}
4253

4354
export interface ClientUnaryCall extends Call {}
@@ -48,6 +59,9 @@ export class ClientUnaryCallImpl extends EventEmitter implements Call {
4859
call.on('metadata', (metadata: Metadata) => {
4960
this.emit('metadata', metadata);
5061
});
62+
call.on('status', (status: StatusObject) => {
63+
this.emit('status', status);
64+
});
5165
}
5266

5367
cancel(): void {
@@ -70,17 +84,6 @@ export interface ClientReadableStream<ResponseType> extends
7084
prependListener(event: string, listener: Function): this;
7185
prependOnceListener(event: string, listener: Function): this;
7286
removeListener(event: string, listener: Function): this;
73-
74-
addListener(event: 'status', listener: (status: StatusObject) => void): this;
75-
emit(event: 'status', status: StatusObject): boolean;
76-
on(event: 'status', listener: (status: StatusObject) => void): this;
77-
once(event: 'status', listener: (status: StatusObject) => void): this;
78-
prependListener(event: 'status', listener: (status: StatusObject) => void):
79-
this;
80-
prependOnceListener(
81-
event: 'status', listener: (status: StatusObject) => void): this;
82-
removeListener(event: 'status', listener: (status: StatusObject) => void):
83-
this;
8487
}
8588

8689
export interface ClientWritableStream<RequestType> extends

packages/grpc-js-core/src/deadline-filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const units: [string, number][] =
99

1010
function getDeadline(deadline: number) {
1111
let now = (new Date()).getTime();
12-
let timeoutMs = deadline - now;
12+
let timeoutMs = Math.max(deadline - now, 0);
1313
for (let [unit, factor] of units) {
1414
let amount = timeoutMs / factor;
1515
if (amount < 1e8) {

0 commit comments

Comments
 (0)