-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make keep_alive configurable in the Web version (#220)
- Loading branch information
Showing
3 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/client-web/__tests__/integration/web_connection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createClient } from '../../src' | ||
import type { WebClickHouseClient } from '../../src/client' | ||
|
||
describe('[Web] Connection', () => { | ||
describe('KeepAlive setting', () => { | ||
let fetchSpy: jasmine.Spy<typeof window.fetch> | ||
beforeEach(() => { | ||
fetchSpy = spyOn(window, 'fetch').and.returnValue( | ||
Promise.resolve(new Response()) | ||
) | ||
}) | ||
|
||
it('should be enabled by default', async () => { | ||
const client = createClient() | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams.keepalive).toBeTruthy() | ||
}) | ||
|
||
it('should be possible to disable it', async () => { | ||
const client = createClient({ keep_alive: { enabled: false } }) | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams!.keepalive).toBeFalsy() | ||
}) | ||
|
||
it('should be enabled with an explicit setting', async () => { | ||
const client = createClient({ keep_alive: { enabled: true } }) | ||
const fetchParams = await pingAndGetRequestInit(client) | ||
expect(fetchParams.keepalive).toBeTruthy() | ||
}) | ||
|
||
async function pingAndGetRequestInit(client: WebClickHouseClient) { | ||
await client.ping() | ||
expect(fetchSpy).toHaveBeenCalledTimes(1) | ||
const [, fetchParams] = fetchSpy.calls.mostRecent().args | ||
return fetchParams! | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters