Skip to content

test(NODE-6084): add search indexes prose test 6 #4091

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

Merged
merged 2 commits into from
Apr 22, 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
1 change: 1 addition & 0 deletions .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ tasks:
- { key: NODE_LTS_VERSION, value: "20" }
- func: install dependencies
- command: subprocess.exec
type: test
params:
working_dir: src
binary: bash
Expand Down
1 change: 1 addition & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ tasks:
- {key: NODE_LTS_VERSION, value: '20'}
- func: install dependencies
- command: subprocess.exec
type: test
params:
working_dir: src
binary: bash
Expand Down
73 changes: 65 additions & 8 deletions test/manual/search-index-management.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Readable } from 'stream';
import { clearTimeout, setTimeout as setTimeoutCb } from 'timers';
import { setInterval } from 'timers/promises';

import { type Collection, type Document, type MongoClient, ObjectId } from '../mongodb';
import {
type Collection,
type Document,
type MongoClient,
ObjectId,
ReadConcern
} from '../mongodb';

class TimeoutController extends AbortController {
timeoutId: NodeJS.Timeout;
Expand Down Expand Up @@ -46,10 +52,12 @@ describe('Index Management Prose Tests', function () {
*/
function waitForIndexes({
predicate,
indexNames
indexNames,
collection
}: {
predicate: (arg0: Array<Document>) => boolean;
indexNames: string | string[];
collection: Collection;
}): Promise<Array<Document>> {
const names = new Set([indexNames].flat());
return Readable.from(
Expand Down Expand Up @@ -112,7 +120,8 @@ describe('Index Management Prose Tests', function () {
// 1. An index with the name of test-search-index is present and the index has a field queryable with a value of true.
const [index] = await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable),
indexNames: 'test-search-index'
indexNames: 'test-search-index',
collection
});

// Assert that index has a property latestDefinition whose value is { 'mappings': { 'dynamic': false } }
Expand Down Expand Up @@ -165,7 +174,8 @@ describe('Index Management Prose Tests', function () {
// 2. An index with the name of test-search-index-2 is present and index has a field queryable with the value of true. Store result in index2.
const indexes = await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable),
indexNames: ['test-search-index-1', 'test-search-index-2']
indexNames: ['test-search-index-1', 'test-search-index-2'],
collection
});

const index1 = indexes.find(({ name }) => name === 'test-search-index-1');
Expand Down Expand Up @@ -203,7 +213,8 @@ describe('Index Management Prose Tests', function () {
// 1. An index with the name of test-search-index is present and index has a field queryable with the value of true.
await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable),
indexNames: 'test-search-index'
indexNames: 'test-search-index',
collection
});

// Run a dropSearchIndex on coll0, using test-search-index for the name.
Expand All @@ -213,7 +224,8 @@ describe('Index Management Prose Tests', function () {
// This test fails if it times out waiting for the deletion to succeed.
const indexes = await waitForIndexes({
predicate: indexes => indexes.length === 0,
indexNames: 'test-search-index'
indexNames: 'test-search-index',
collection
});

expect(indexes).to.deep.equal([]);
Expand Down Expand Up @@ -241,7 +253,8 @@ describe('Index Management Prose Tests', function () {
// 1. An index with the name of test-search-index is present and index has a field queryable with the value of true.
await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable),
indexNames: 'test-search-index'
indexNames: 'test-search-index',
collection
});

// Run a updateSearchIndex on coll0, using the following definition.
Expand All @@ -261,7 +274,8 @@ describe('Index Management Prose Tests', function () {
// 2. The index has a field queryable with a value of true and has a field status with the value of READY.
const [index2] = await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable && index.status === 'READY'),
indexNames: 'test-search-index'
indexNames: 'test-search-index',
collection
});

// Assert that an index is present with the name test-search-index and the definition has a
Expand All @@ -283,5 +297,48 @@ describe('Index Management Prose Tests', function () {
await collection.dropSearchIndex('test-search-index');
}
);

it(
'Case 6: Driver can successfully create and list search indexes with non-default readConcern and writeConcern',
metadata,
async function () {
// 1. Create a collection with the "create" command using a randomly generated name (referred to as coll0).
// 2. Apply a write concern WriteConcern(w=1) and a read concern with ReadConcern(level="majority") to coll0.
const coll0 = await client.db('node-test').createCollection(new ObjectId().toHexString(), {
readConcern: ReadConcern.MAJORITY,
writeConcern: { w: 1 }
});

// 3. Create a new search index on coll0 with the createSearchIndex helper. Use the following definition:
// {
// name: 'test-search-index-case6',
// definition: {
// mappings: { dynamic: false }
// }
// }
const name = await coll0.createSearchIndex({
name: 'test-search-index-case6',
definition: {
mappings: { dynamic: false }
}
});

// 4. Assert that the command returns the name of the index: "test-search-index-case6".
expect(name).to.equal('test-search-index-case6');

// 5. Run coll0.listSearchIndexes() repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable index:
// - An index with the name of test-search-index-case6 is present and the index has a field queryable with a value of true.
const [index] = await waitForIndexes({
predicate: indexes => indexes.every(index => index.queryable),
indexNames: 'test-search-index-case6',
collection: coll0
});

// 6. Assert that index has a property latestDefinition whose value is { 'mappings': { 'dynamic': false } }
expect(index)
.to.have.nested.property('latestDefinition.mappings')
.to.deep.equal({ dynamic: false });
}
);
});
});