Skip to content

Commit 9a6deb9

Browse files
bors[bot]bidoubiwa
andauthored
Merge #683
683: Improve dump tests r=bidoubiwa a=bidoubiwa Add test util `waitForDumpProcessing`. It is a function only existing for test purposes. Naming can change. Fix failing tests Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents 0383498 + 2617655 commit 9a6deb9

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

tests/dump_tests.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
privateClient,
77
publicClient,
88
anonymousClient,
9+
waitForDumpProcessing,
910
} from './meilisearch-test-utils'
1011

1112
beforeAll(async () => {
@@ -17,18 +18,18 @@ describe.each([
1718
{ client: privateClient, permission: 'Private' },
1819
])('Test on dump', ({ client, permission }) => {
1920
test(`${permission} key: create a new dump`, async () => {
20-
await client.createDump().then((response) => {
21-
expect(response.uid).toBeDefined()
22-
expect(response.status).toEqual('in_progress')
23-
})
21+
const response = await client.createDump()
22+
expect(response.uid).toBeDefined()
23+
expect(response.status).toEqual('in_progress')
24+
await waitForDumpProcessing(response.uid, client)
2425
})
2526

2627
test(`${permission} key: get dump status`, async () => {
2728
const enqueuedDump = await client.createDump()
28-
await client.getDumpStatus(enqueuedDump.uid).then((response) => {
29-
expect(response.uid).toEqual(enqueuedDump.uid)
30-
expect(response.status).toBeDefined()
31-
})
29+
await waitForDumpProcessing(enqueuedDump.uid, client)
30+
const response = await client.getDumpStatus(enqueuedDump.uid)
31+
expect(response.uid).toEqual(enqueuedDump.uid)
32+
expect(response.status).toBeDefined()
3233
})
3334
})
3435

tests/env/express/tests/client.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ describe('MeiliSearch JS Browser test', () => {
44
})
55

66
it('Should have generated a meilisearch client and displayed', async () => {
7+
jest.setTimeout(100 * 1000)
78
await page.waitForSelector("#indexes")
89
await expect(
910
page.content()

tests/meilisearch-test-utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MeiliSearch from '../src/meilisearch'
22
import * as Types from '../src/types'
3+
import { sleep } from '../src/utils'
34

45
// testing
56
const MASTER_KEY = 'masterKey'
@@ -49,6 +50,25 @@ const clearAllIndexes = async (config: Types.Config): Promise<void> => {
4950
await expect(client.listIndexes()).resolves.toHaveLength(0)
5051
}
5152

53+
async function waitForDumpProcessing(
54+
dumpId: string,
55+
client: MeiliSearch,
56+
{
57+
timeOutMs = 5000,
58+
intervalMs = 50,
59+
}: { timeOutMs?: number; intervalMs?: number } = {}
60+
): Promise<Types.EnqueuedDump> {
61+
const startingTime = Date.now()
62+
while (Date.now() - startingTime < timeOutMs) {
63+
const response = await client.getDumpStatus(dumpId)
64+
if (response.status !== 'in_progress') return response
65+
await sleep(intervalMs)
66+
}
67+
throw new Types.MeiliSearchTimeOutError(
68+
`timeout of ${timeOutMs}ms has exceeded on process ${dumpId} when waiting for the dump creation process to be done.`
69+
)
70+
}
71+
5272
export {
5373
clearAllIndexes,
5474
config,
@@ -60,4 +80,5 @@ export {
6080
PRIVATE_KEY,
6181
MASTER_KEY,
6282
MeiliSearch,
83+
waitForDumpProcessing,
6384
}

0 commit comments

Comments
 (0)