Skip to content

Commit 0d092d9

Browse files
committed
Add DgraphClientStub#waitForReady
1 parent 75939d6 commit 0d092d9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/clientStub.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class DgraphClientStub {
1616
mutate(mu: messages.Mutation): Promise<messages.Assigned>;
1717
commitOrAbort(ctx: messages.TxnContext): Promise<messages.TxnContext>;
1818
checkVersion(check: messages.Check): Promise<messages.Version>;
19+
waitForReady(deadline: grpc.Deadline): Promise<void>;
1920
};
2021

2122
constructor(addr?: string | null, credentials?: grpc.ChannelCredentials | null) {
@@ -35,6 +36,7 @@ export class DgraphClientStub {
3536
mutate: promisify(this.stub.mutate, this.stub),
3637
commitOrAbort: promisify(this.stub.commitOrAbort, this.stub),
3738
checkVersion: promisify(this.stub.checkVersion, this.stub),
39+
waitForReady: promisify(this.stub.waitForReady, this.stub),
3840
};
3941
}
4042

@@ -58,6 +60,10 @@ export class DgraphClientStub {
5860
return this.promisified.checkVersion(check);
5961
}
6062

63+
public waitForReady(deadline: grpc.Deadline): Promise<void> {
64+
return this.promisified.waitForReady(deadline);
65+
}
66+
6167
public close(): void {
6268
return this.stub.close();
6369
}

tests/clientStub.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as dgraph from "../src";
22

3-
import { setup } from "./helper";
3+
import { SERVER_ADDR, SERVER_CREDENTIALS, setup } from "./helper";
44

55
async function checkVersion(stub: dgraph.DgraphClientStub): Promise<void> {
66
const v = await stub.checkVersion(new dgraph.Check());
@@ -24,10 +24,17 @@ describe("clientStub", () => {
2424
});
2525
});
2626

27+
describe("waitForReady", () => {
28+
it("should provide a promisified version of grpc.Client#waitForReady", async () => {
29+
const clientStub = new dgraph.DgraphClientStub(SERVER_ADDR, SERVER_CREDENTIALS);
30+
await clientStub.waitForReady(Date.now() + 500);
31+
await checkVersion(clientStub);
32+
});
33+
});
34+
2735
describe("close", () => {
2836
it("should close channel", async () => {
29-
const client = await setup();
30-
const clientStub = await client.anyClient();
37+
const clientStub = new dgraph.DgraphClientStub(SERVER_ADDR, SERVER_CREDENTIALS);
3138
clientStub.close();
3239
const p = clientStub.checkVersion(new dgraph.Check());
3340
await expect(p).rejects.toBeDefined();

0 commit comments

Comments
 (0)