Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to check connection #341

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ const password = 'your-milvus-password'; // optional password

// connect to milvus
const client = new MilvusClient({ address, username, password });
// wait until connecting finished
await client.connectPromise;
```

### Create a collection
Expand Down
4 changes: 4 additions & 0 deletions milvus/grpc/GrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export class GRPCClient extends User {
* This method returns a Promise that resolves with a `GetVersionResponse` object.
*/
async getVersion(): Promise<GetVersionResponse> {
// wait until connecting finished
await this.connectPromise;
return await promisify(this.channelPool, 'GetVersion', {}, this.timeout);
}

Expand All @@ -252,6 +254,8 @@ export class GRPCClient extends User {
* This method returns a Promise that resolves with a `CheckHealthResponse` object.
*/
async checkHealth(): Promise<CheckHealthResponse> {
// wait until connecting finished
await this.connectPromise;
return await promisify(this.channelPool, 'CheckHealth', {}, this.timeout);
}
}
8 changes: 8 additions & 0 deletions test/grpc/MilvusClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ describe(`Milvus client`, () => {
expect(Array.isArray(res.reasons)).toBe(true);
});

it(`Should throw when server is unavailable`, async () => {
const m10 = new MilvusClient({ address: IP.replace(':19530', ':19539') });
await expect(m10.connectPromise).rejects.toThrow('UNAVAILABLE');
await expect(m10.getVersion()).rejects.toThrow('UNAVAILABLE');
await expect(m10.checkCompatibility()).rejects.toThrow('UNAVAILABLE');
await expect(m10.checkHealth()).rejects.toThrow('UNAVAILABLE');
});

it(`Expect close connection success`, async () => {
expect(milvusClient.channelPool.size).toBeGreaterThan(0);

Expand Down
Loading