Skip to content

Commit

Permalink
feat(ws-transport): Introduce close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Apr 15, 2021
1 parent 48664e7 commit 47394c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/cubejs-client-ws-transport/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare module '@cubejs-client/ws-transport' {
protected messageQueue: Message[];
constructor({ authorization, apiUrl, heartBeatInterval, hearBeatInterval }: WebSocketTransportOptions);
set authorization(token: string | undefined);
close(): Promise<void>;
get authorization(): string | undefined;
protected initSocket(): any;
protected sendMessage(message: any): void;
Expand Down
6 changes: 6 additions & 0 deletions packages/cubejs-client-ws-transport/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class WebSocketTransport implements ITransport<WebSocketTransportResult> {
}
}

public async close(): Promise<void> {
if (this.ws) {
this.ws.close();
}
}

public get authorization() {
return this.token;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cubejs-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"birdbox:postgresql:snapshot": "jest --verbose --updateSnapshot -i dist/test/birdbox-postgresql.test.js",
"birdbox:postgresql-cubestore": "jest --verbose -i dist/test/birdbox-postgresql-cubestore.test.js",
"birdbox:postgresql-cubestore:snapshot": "jest --verbose --updateSnapshot -i dist/test/birdbox-postgresql-cubestore.test.js",
"birdbox:cli:postgresql": "jest --verbose -i dist/test/cli-postgresql.test.js",
"birdbox:cli:postgresql:snapshot": "jest --verbose --updateSnapshot -i dist/test/cli-postgresql.test.js",
"birdbox:cli:postgresql": "jest --forceExit --verbose -i dist/test/cli-postgresql.test.js",
"birdbox:cli:postgresql:snapshot": "jest --forceExit --verbose --updateSnapshot -i dist/test/cli-postgresql.test.js",
"cypress:install": "cypress install",
"cypress:birdbox": "node dist/test/bin/cypress-birdbox.js"
},
Expand Down
10 changes: 7 additions & 3 deletions packages/cubejs-testing/test/abstract-test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function createBirdBoxTestCase(name: string, entrypoint: () => Promise<Bi
let birdbox: BirdBox;
let httpClient: CubejsApi;
let wsClient: CubejsApi;
let wsTransport: WebSocketTransport;

// eslint-disable-next-line consistent-return
beforeAll(async () => {
Expand All @@ -76,11 +77,12 @@ export function createBirdBoxTestCase(name: string, entrypoint: () => Promise<Bi
apiUrl: birdbox.configuration.apiUrl,
});

wsTransport = new WebSocketTransport({
apiUrl: birdbox.configuration.apiUrl,
});
wsClient = cubejs(async () => 'test', {
apiUrl: birdbox.configuration.apiUrl,
transport: new WebSocketTransport({
apiUrl: birdbox.configuration.apiUrl,
}),
transport: wsTransport,
});
} catch (e) {
console.log(e);
Expand All @@ -90,6 +92,8 @@ export function createBirdBoxTestCase(name: string, entrypoint: () => Promise<Bi

// eslint-disable-next-line consistent-return
afterAll(async () => {
await wsTransport.close();

await birdbox.stop();
});

Expand Down

0 comments on commit 47394c1

Please sign in to comment.