Skip to content

Commit d975307

Browse files
list search index tests working on atlas
1 parent a329748 commit d975307

24 files changed

+367
-80
lines changed

.evergreen/config.in.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ functions:
4545
params:
4646
file: src/expansion.yml
4747

48-
"run search index management tests":
49-
- command: subprocess.exec
50-
params:
51-
binary: bash
52-
working_dir: src
53-
add_expansions_to_env: true
54-
args:
55-
- .evergreen/run-search-index-management-tests.sh
56-
5748
"bootstrap mongo-orchestration":
5849
- command: subprocess.exec
5950
params:
@@ -1273,6 +1264,19 @@ tasks:
12731264
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/test/lambda
12741265
AWS_REGION: us-east-1
12751266

1267+
- name: test-search-index-helpers
1268+
commands:
1269+
- func: install dependencies
1270+
vars:
1271+
NODE_LTS_VERSION: 20
1272+
- command: subprocess.exec
1273+
params:
1274+
working_dir: src
1275+
binary: bash
1276+
add_expansions_to_env: true
1277+
args:
1278+
- .evergreen/run-search-index-management-tests.sh
1279+
12761280
task_groups:
12771281
- name: serverless_task_group
12781282
setup_group_can_fail_task: true
@@ -1412,6 +1416,8 @@ task_groups:
14121416
working_dir: src
14131417
binary: bash
14141418
add_expansions_to_env: true
1419+
env:
1420+
MONGODB_VERSION: "7.0"
14151421
args:
14161422
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
14171423
- command: expansions.update
@@ -1429,6 +1435,7 @@ task_groups:
14291435
setup_group_timeout_secs: 1800
14301436
tasks:
14311437
- test-aws-lambda-deployed
1438+
- test-search-index-helpers
14321439

14331440
pre:
14341441
- func: "fetch source"

.evergreen/config.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ functions:
2525
- command: expansions.update
2626
params:
2727
file: src/expansion.yml
28-
run search index management tests:
29-
- command: subprocess.exec
30-
params:
31-
binary: bash
32-
working_dir: src
33-
add_expansions_to_env: true
34-
args:
35-
- .evergreen/run-search-index-management-tests.sh
3628
bootstrap mongo-orchestration:
3729
- command: subprocess.exec
3830
params:
@@ -1196,6 +1188,18 @@ tasks:
11961188
env:
11971189
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/test/lambda
11981190
AWS_REGION: us-east-1
1191+
- name: test-search-index-helpers
1192+
commands:
1193+
- func: install dependencies
1194+
vars:
1195+
NODE_LTS_VERSION: 20
1196+
- command: subprocess.exec
1197+
params:
1198+
working_dir: src
1199+
binary: bash
1200+
add_expansions_to_env: true
1201+
args:
1202+
- .evergreen/run-search-index-management-tests.sh
11991203
- name: test-latest-server
12001204
tags:
12011205
- latest
@@ -2643,17 +2647,6 @@ tasks:
26432647
variant: '*'
26442648
status: '*'
26452649
patch_optional: true
2646-
- name: test-search-index-helpers
2647-
tags: []
2648-
commands:
2649-
- func: install dependencies
2650-
vars:
2651-
NODE_LTS_NAME: 20
2652-
- func: bootstrap mongo-orchestration
2653-
vars:
2654-
VERSION: latest
2655-
TOPOLOGY: replica_set
2656-
- func: run search index management tests
26572650
- name: run-custom-csfle-tests-5.0-pinned-commit
26582651
tags:
26592652
- run-custom-dependency-tests
@@ -3465,6 +3458,8 @@ task_groups:
34653458
working_dir: src
34663459
binary: bash
34673460
add_expansions_to_env: true
3461+
env:
3462+
MONGODB_VERSION: '7.0'
34683463
args:
34693464
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
34703465
- command: expansions.update
@@ -3482,6 +3477,7 @@ task_groups:
34823477
setup_group_timeout_secs: 1800
34833478
tasks:
34843479
- test-aws-lambda-deployed
3480+
- test-search-index-helpers
34853481
pre:
34863482
- func: fetch source
34873483
- func: windows fix
@@ -4110,8 +4106,3 @@ buildvariants:
41104106
tasks:
41114107
- test-lambda-example
41124108
- test-lambda-aws-auth-example
4113-
- name: rhel8-test-seach-index-management-helpers
4114-
display_name: Search Index Management Helpers Tests
4115-
run_on: rhel80-large
4116-
tasks:
4117-
- test-search-index-helpers

.evergreen/generate_evergreen_tasks.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -690,26 +690,6 @@ const coverageTask = {
690690
};
691691

692692
SINGLETON_TASKS.push(coverageTask);
693-
SINGLETON_TASKS.push({
694-
name: 'test-search-index-helpers',
695-
tags: [],
696-
commands: [
697-
{
698-
func: 'install dependencies',
699-
vars: {
700-
NODE_LTS_NAME: LATEST_LTS
701-
}
702-
},
703-
{
704-
func: 'bootstrap mongo-orchestration',
705-
vars: {
706-
VERSION: 'latest',
707-
TOPOLOGY: 'replica_set'
708-
}
709-
},
710-
{ func: 'run search index management tests' }
711-
]
712-
})
713693
SINGLETON_TASKS.push(...oneOffFuncAsTasks);
714694

715695
BUILD_VARIANTS.push({
@@ -777,13 +757,6 @@ BUILD_VARIANTS.push({
777757
tasks: ['test-lambda-example', 'test-lambda-aws-auth-example']
778758
});
779759

780-
BUILD_VARIANTS.push({
781-
name: 'rhel8-test-seach-index-management-helpers',
782-
display_name: 'Search Index Management Helpers Tests',
783-
run_on: DEFAULT_OS,
784-
tasks: ['test-search-index-helpers']
785-
})
786-
787760
// TODO(NODE-4575): unskip zstd and snappy on node 16
788761
for (const variant of BUILD_VARIANTS.filter(
789762
variant =>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"check:tsd": "tsd --version && tsd",
130130
"check:dependencies": "mocha test/action/dependency.test.ts",
131131
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
132-
"check:search-indexes": "nyc mocha --config test/mocha_mongodb.json test/manual/search-index-management.spec.test.ts",
132+
"check:search-indexes": "nyc mocha --config test/mocha_mongodb.json test/manual/search-index-management.prose.*",
133133
"check:test": "mocha --config test/mocha_mongodb.json test/integration",
134134
"check:unit": "mocha test/unit",
135135
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",

src/operations/search_indexes/drop.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Document } from 'bson';
22

33
import type { Collection } from '../../collection';
4+
import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
45
import type { Server } from '../../sdam/server';
56
import type { ClientSession } from '../../sessions';
67
import type { Callback } from '../../utils';
@@ -28,7 +29,9 @@ export class DropSearchIndexOperation extends AbstractCallbackOperation<void> {
2829
}
2930

3031
server.command(namespace, command, { session }, err => {
31-
if (err) {
32+
const isNamespaceNotFoundError =
33+
err instanceof MongoServerError && err.code === MONGODB_ERROR_CODES.NamespaceNotFound;
34+
if (err && !isNamespaceNotFoundError) {
3235
callback(err);
3336
return;
3437
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import { expect } from 'chai';
2+
import { lt } from 'semver';
3+
import { Readable } from 'stream';
4+
import { clearTimeout, setTimeout as setTimeoutCb } from 'timers';
5+
import { setInterval } from 'timers/promises';
6+
7+
import { type Collection, type Document, type MongoClient, ObjectId } from '../mongodb';
8+
9+
class TimeoutController extends AbortController {
10+
constructor(private timeoutMS: number) {
11+
super();
12+
13+
this.timeoutId = setTimeoutCb(() => {
14+
this.abort(new Error(`Test timed out after ${timeoutMS} milliseconds.`));
15+
}, timeoutMS);
16+
}
17+
18+
clear(abort = false) {
19+
if (abort) {
20+
this.abort();
21+
}
22+
clearTimeout(this.timeoutId);
23+
}
24+
}
25+
26+
describe('Index Management Prose Tests', function () {
27+
describe('Search Index Management Tests', function () {
28+
this.timeout(300000); // set timeout at two minutes
29+
30+
let client: MongoClient;
31+
let timeoutController: TimeoutController;
32+
33+
const interval = (interval: number, signal: AbortSignal) =>
34+
Readable.from(setInterval(interval, undefined, { signal, ref: false }));
35+
36+
const waitForIndexes = (
37+
collection: Collection,
38+
predicate: (arg0: Array<Document>) => boolean,
39+
indexName?: string
40+
): Promise<Array<Document>> =>
41+
interval(5000, timeoutController.signal)
42+
.map(() => collection.listSearchIndexes(indexName).toArray())
43+
.find(predicate);
44+
45+
before(function () {
46+
this.configuration = this.configuration.makeAtlasTestConfiguration();
47+
});
48+
49+
beforeEach(function () {
50+
if (lt(process.version, '18.0')) {
51+
this.currentTest!.skipReason = 'Test requires Node18+';
52+
this.skip();
53+
}
54+
});
55+
56+
beforeEach(async function () {
57+
client = this.configuration.newClient();
58+
await client.connect();
59+
60+
timeoutController = new TimeoutController(60 * 1000 * 4);
61+
});
62+
63+
afterEach(async () => {
64+
await client.close();
65+
timeoutController.clear(false);
66+
});
67+
68+
it('Case 1: Driver can successfully create and list search indexes', async function () {
69+
const collection = await client.db('test-db').createCollection(new ObjectId().toHexString());
70+
71+
await collection.createSearchIndex({
72+
name: 'test-search-index',
73+
definition: {
74+
mappings: { dynamic: false }
75+
}
76+
});
77+
78+
const [index] = await waitForIndexes(
79+
collection,
80+
indexes => indexes.every(index => index.queryable),
81+
'test-search-index'
82+
);
83+
84+
expect(index).to.exist;
85+
expect(index)
86+
.to.have.property('latestDefinition')
87+
.to.deep.equal({ mappings: { dynamic: false } });
88+
});
89+
90+
it('Case 2: Driver can successfully create multiple indexes in batch', async function () {
91+
const collection = await client.db('test-db').createCollection(new ObjectId().toHexString());
92+
93+
const indexDefinitions = [
94+
{
95+
name: 'test-search-index-1',
96+
definition: {
97+
mappings: { dynamic: false }
98+
}
99+
},
100+
{
101+
name: 'test-search-index-2',
102+
definition: {
103+
mappings: { dynamic: false }
104+
}
105+
}
106+
];
107+
108+
await collection.createSearchIndexes(indexDefinitions);
109+
110+
const indexes = await waitForIndexes(collection, indexes =>
111+
indexes.every(index => index.queryable)
112+
);
113+
114+
for (const indexDescription of indexDefinitions) {
115+
const index = indexes.find(({ name }) => name === indexDescription.name);
116+
expect(index, `expected ${indexDescription.name} to exist`).to.exist;
117+
118+
expect(index)
119+
.to.have.property('latestDefinition')
120+
.to.deep.equal({ mappings: { dynamic: false } });
121+
}
122+
});
123+
124+
it('Case 3: Driver can successfully drop search indexes', async function () {
125+
const collection = await client.db('test-db').createCollection(new ObjectId().toHexString());
126+
127+
await collection.createSearchIndex({
128+
name: 'test-search-index',
129+
definition: {
130+
mappings: { dynamic: false }
131+
}
132+
});
133+
134+
await waitForIndexes(
135+
collection,
136+
indexes => indexes.every(index => index.queryable),
137+
'test-search-index'
138+
);
139+
140+
await collection.dropSearchIndex('test-search-index');
141+
142+
const indexes = await waitForIndexes(
143+
collection,
144+
indexes => indexes.length === 0,
145+
'test-search-index'
146+
);
147+
148+
expect(indexes).to.deep.equal([]);
149+
});
150+
151+
it('Case 4: Driver can update a search index', async function () {
152+
const collection = await client.db('test-db').createCollection(new ObjectId().toHexString());
153+
154+
await collection.createSearchIndex({
155+
name: 'test-search-index',
156+
definition: {
157+
mappings: { dynamic: false }
158+
}
159+
});
160+
161+
await waitForIndexes(
162+
collection,
163+
indexes => indexes.every(index => index.queryable),
164+
'test-search-index'
165+
);
166+
167+
await collection.updateSearchIndex('test-search-index', { mappings: { dynamic: true } });
168+
169+
const [updatedIndex] = await waitForIndexes(
170+
collection,
171+
indexes => indexes.every(index => index.queryable && index.status === 'READY'),
172+
'test-search-index'
173+
);
174+
175+
expect(updatedIndex).to.have.property('name', 'test-search-index');
176+
expect(updatedIndex)
177+
.to.have.property('latestDefinition')
178+
.to.deep.equal({ mappings: { dynamic: true } });
179+
});
180+
181+
it('Case 5: `dropSearchIndex` suppresses namespace not found errors', async function () {
182+
const collection = await client.db('test-db').collection(new ObjectId().toHexString());
183+
184+
await collection.dropSearchIndex('test-search-index');
185+
});
186+
});
187+
});

test/manual/search-index-management.spec.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ import { loadSpecTests } from '../spec';
44
import { runUnifiedSuite } from '../tools/unified-spec-runner/runner';
55

66
describe('Search Index Management Tests (Unified)', function () {
7+
before(function () {
8+
this.configuration = this.configuration.makeAtlasTestConfiguration();
9+
});
710
runUnifiedSuite(loadSpecTests(join('index-management')));
811
});

0 commit comments

Comments
 (0)