Skip to content

Commit c2948f5

Browse files
committed
test(cbjs): apply timeout to internal waitForX
1 parent 60a9aa9 commit c2948f5

File tree

1 file changed

+65
-54
lines changed

1 file changed

+65
-54
lines changed

tests/cbjs/tests/search.spec.ts

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
SearchIndexNotFoundError,
2323
SearchQuery,
2424
} from '@cbjsdev/cbjs';
25-
import { ServerFeatures } from '@cbjsdev/http-client';
25+
import { ServerFeatures, waitForCollection } from '@cbjsdev/http-client';
2626
import { invariant, sleep, waitFor } from '@cbjsdev/shared';
2727
import { createCouchbaseTest } from '@cbjsdev/vitest';
2828

@@ -122,6 +122,7 @@ describe
122122
'should see test data correctly',
123123
{ timeout: 60_000 },
124124
async ({
125+
apiConfig,
125126
serverTestContext,
126127
useCollection,
127128
useSearchIndex,
@@ -147,22 +148,25 @@ describe
147148
awaitMutations: true,
148149
});
149150

150-
await waitFor(async () => {
151-
const result = await serverTestContext.cluster.searchQuery(
152-
indexName,
153-
SearchQuery.term(sampleData.testUid).field('testUid'),
154-
{ explain: true, fields: ['name'] }
155-
);
156-
157-
expect(result.rows).toBeInstanceOf(Array);
158-
expect(result.rows).toHaveLength(sampleData.sampleSize);
159-
160-
result.rows.forEach((row) => {
161-
expect(row.index).toBeTypeOf('string');
162-
expect(row.id).toBeTypeOf('string');
163-
expect(row.score).toBeTypeOf('number');
164-
});
165-
});
151+
await waitFor(
152+
async () => {
153+
const result = await serverTestContext.cluster.searchQuery(
154+
indexName,
155+
SearchQuery.term(sampleData.testUid).field('testUid'),
156+
{ explain: true, fields: ['name'] }
157+
);
158+
159+
expect(result.rows).toBeInstanceOf(Array);
160+
expect(result.rows).toHaveLength(sampleData.sampleSize);
161+
162+
result.rows.forEach((row) => {
163+
expect(row.index).toBeTypeOf('string');
164+
expect(row.id).toBeTypeOf('string');
165+
expect(row.score).toBeTypeOf('number');
166+
});
167+
},
168+
{ timeout: 20_000, retryInterval: 100 }
169+
);
166170
}
167171
);
168172

@@ -328,47 +332,54 @@ describe
328332
}
329333
});
330334

331-
test('should disable scoring', async ({
332-
serverTestContext,
333-
expect,
334-
useCollection,
335-
useSearchIndex,
336-
useSampleData,
337-
}) => {
338-
expect.hasAssertions();
339-
340-
const collectionName = await useCollection();
341-
await sleep(2_000);
342-
343-
const collection = serverTestContext.bucket.collection(collectionName);
335+
test(
336+
'should disable scoring',
337+
{ timeout: 60_000 },
338+
async ({
339+
serverTestContext,
340+
expect,
341+
useCollection,
342+
useSearchIndex,
343+
useSampleData,
344+
}) => {
345+
expect.hasAssertions();
344346

345-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
346-
const { name, ...indexConfig } = getSearchIndexConfig(
347-
'willBeRemovedAndRandomized',
348-
collection.getKeyspace()
349-
);
347+
const collectionName = await useCollection();
348+
await sleep(2_000);
350349

351-
const sampleData = await useSampleData(collection);
352-
const indexName = await useSearchIndex(indexConfig, {
353-
waitSearchIndexTimeout: 55_000,
354-
awaitMutations: true,
355-
});
350+
const collection = serverTestContext.bucket.collection(collectionName);
356351

357-
await waitFor(async () => {
358-
const result = await serverTestContext.cluster.searchQuery(
359-
indexName,
360-
SearchQuery.term(sampleData.testUid).field('testUid'),
361-
{ disableScoring: true }
352+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
353+
const { name, ...indexConfig } = getSearchIndexConfig(
354+
'willBeRemovedAndRandomized',
355+
collection.getKeyspace()
362356
);
363357

364-
expect(result.rows).toBeInstanceOf(Array);
365-
expect(result.rows).toHaveLength(sampleData.sampleSize);
366-
367-
result.rows.forEach((row) => {
368-
expect(row.index).toBeTypeOf('string');
369-
expect(row.id).toBeTypeOf('string');
370-
expect(row.score).toEqual(0);
358+
const sampleData = await useSampleData(collection);
359+
const indexName = await useSearchIndex(indexConfig, {
360+
waitSearchIndexTimeout: 55_000,
361+
awaitMutations: true,
371362
});
372-
});
373-
});
363+
364+
await waitFor(
365+
async () => {
366+
const result = await serverTestContext.cluster.searchQuery(
367+
indexName,
368+
SearchQuery.term(sampleData.testUid).field('testUid'),
369+
{ disableScoring: true }
370+
);
371+
372+
expect(result.rows).toBeInstanceOf(Array);
373+
expect(result.rows).toHaveLength(sampleData.sampleSize);
374+
375+
result.rows.forEach((row) => {
376+
expect(row.index).toBeTypeOf('string');
377+
expect(row.id).toBeTypeOf('string');
378+
expect(row.score).toEqual(0);
379+
});
380+
},
381+
{ timeout: 20_000 }
382+
);
383+
}
384+
);
374385
});

0 commit comments

Comments
 (0)