Skip to content

Commit 6a86553

Browse files
authored
test(NODE-4534): unified SDAM test runner implementation (#3373)
1 parent 3fe6a24 commit 6a86553

File tree

124 files changed

+8303
-5073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+8303
-5073
lines changed

test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.js

-80
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
import { Socket } from 'net';
3+
import * as path from 'path';
4+
5+
import { loadSpecTests } from '../../spec';
6+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
7+
import { TestFilter } from '../../tools/unified-spec-runner/schema';
8+
import { sleep } from '../../tools/utils';
9+
10+
const filter: TestFilter = ({ description }) => {
11+
const isAuthEnabled = process.env.AUTH === 'auth';
12+
switch (description) {
13+
case 'Reset server and pool after AuthenticationFailure error':
14+
case 'Reset server and pool after misc command error':
15+
case 'Reset server and pool after network error during authentication':
16+
case 'Reset server and pool after network timeout error during authentication':
17+
case 'Reset server and pool after shutdown error during authentication':
18+
// These tests time out waiting for the PoolCleared event
19+
return isAuthEnabled ? 'TODO(NODE-3891): fix tests broken when AUTH enabled' : false;
20+
case 'Network error on minPoolSize background creation':
21+
return 'TODO(NODE-4385): implement pool pausing and pool ready event';
22+
default:
23+
return false;
24+
}
25+
};
26+
27+
describe('SDAM Unified Tests', function () {
28+
afterEach(async function () {
29+
// TODO(NODE-4573): fix socket leaks
30+
const LEAKY_TESTS = [
31+
'Command error on Monitor handshake',
32+
'Network error on Monitor check',
33+
'Network timeout on Monitor check',
34+
'Network error on Monitor handshake',
35+
'Network timeout on Monitor handshake'
36+
];
37+
38+
await sleep(250);
39+
const sockArray = (process as any)._getActiveHandles().filter(handle => {
40+
// Stdio are instanceof Socket so look for fd to be null
41+
return handle.fd == null && handle instanceof Socket && handle.destroyed !== true;
42+
});
43+
if (!sockArray.length) {
44+
return;
45+
}
46+
for (const sock of sockArray) {
47+
sock.destroy();
48+
}
49+
if (!LEAKY_TESTS.some(test => test === this.currentTest!.title)) {
50+
this.test!.error(new Error(`Test failed to clean up ${sockArray.length} socket(s)`));
51+
}
52+
});
53+
runUnifiedSuite(loadSpecTests(path.join('server-discovery-and-monitoring', 'unified')), filter);
54+
});

test/spec/server-discovery-and-monitoring/README.rst

+3-190
Original file line numberDiff line numberDiff line change
@@ -188,196 +188,9 @@ Continue until all phases have been executed.
188188
Integration Tests
189189
-----------------
190190

191-
Integration tests are provided in the "integration" directory.
192-
193-
Test Format
194-
~~~~~~~~~~~
195-
196-
The same as the `Transactions Spec Test format
197-
</source/transactions/tests/README.rst#test-format>`_ with the following
198-
additions:
199-
200-
- The ``runOn`` requirement gains a new field:
201-
202-
- ``authEnabled`` (optional): If True, skip this test if auth is not enabled.
203-
If False, skip this test if auth is enabled. If this field is omitted,
204-
this test can be run on clusters with or without auth.
205-
206-
Special Test Operations
207-
~~~~~~~~~~~~~~~~~~~~~~~
208-
209-
Certain operations that appear in the "operations" array do not correspond to
210-
API methods but instead represent special test operations. Such operations are
211-
defined on the "testRunner" object and are documented in the
212-
`Transactions Spec Test
213-
</source/transactions/tests/README.rst#special-test-operations>`_.
214-
215-
Additional, SDAM test specific operations are documented here:
216-
217-
configureFailPoint
218-
''''''''''''''''''
219-
220-
The "configureFailPoint" operation instructs the test runner to configure
221-
the given server failpoint on the "admin" database. The runner MUST disable
222-
this failpoint at the end of the test. For example::
223-
224-
- name: configureFailPoint
225-
object: testRunner
226-
arguments:
227-
failPoint:
228-
configureFailPoint: failCommand
229-
mode: { times: 1 }
230-
data:
231-
failCommands: ["insert"]
232-
closeConnection: true
233-
234-
Tests that use the "configureFailPoint" operation do not include
235-
``configureFailPoint`` commands in their command expectations. Drivers MUST
236-
ensure that ``configureFailPoint`` commands do not appear in the list of logged
237-
commands, either by manually filtering it from the list of observed commands or
238-
by using a different MongoClient to execute ``configureFailPoint``.
239-
240-
Note, similar to the ``tests.failPoint`` field described in the `Transactions
241-
Spec Test format </source/transactions/tests/README.rst#test-format>`_ tests
242-
with ``useMultipleMongoses: true`` will not contain a ``configureFailPoint``
243-
operation.
244-
245-
wait
246-
''''
247-
248-
The "wait" operation instructs the test runner to sleep for "ms"
249-
milliseconds. For example::
250-
251-
- name: wait
252-
object: testRunner
253-
arguments:
254-
ms: 1000
255-
256-
waitForEvent
257-
''''''''''''
258-
259-
The "waitForEvent" operation instructs the test runner to wait until the test's
260-
MongoClient has published a specific event a given number of times. For
261-
example, the following instructs the test runner to wait for at least one
262-
PoolClearedEvent to be published::
263-
264-
- name: waitForEvent
265-
object: testRunner
266-
arguments:
267-
event: PoolClearedEvent
268-
count: 1
269-
270-
Note that "count" includes events that were published while running previous
271-
operations.
272-
273-
If the "waitForEvent" operation is not satisfied after 10 seconds, the
274-
operation is considered an error.
275-
276-
ServerMarkedUnknownEvent
277-
````````````````````````
278-
279-
The ServerMarkedUnknownEvent may appear as an event in `waitForEvent`_ and
280-
`assertEventCount`_. This event is defined as ServerDescriptionChangedEvent
281-
where newDescription.type is ``Unknown``.
282-
283-
assertEventCount
284-
''''''''''''''''
285-
286-
The "assertEventCount" operation instructs the test runner to assert the test's
287-
MongoClient has published a specific event a given number of times. For
288-
example, the following instructs the test runner to assert that a single
289-
PoolClearedEvent was published::
290-
291-
- name: assertEventCount
292-
object: testRunner
293-
arguments:
294-
event: PoolClearedEvent
295-
count: 1
296-
297-
recordPrimary
298-
'''''''''''''
299-
300-
The "recordPrimary" operation instructs the test runner to record the current
301-
primary of the test's MongoClient. For example::
302-
303-
- name: recordPrimary
304-
object: testRunner
305-
306-
runAdminCommand
307-
'''''''''''''''
308-
309-
The "runAdminCommand" operation instructs the test runner to run the given
310-
command on the admin database. Drivers MUST run this command on a different
311-
MongoClient from the one used for test operations. For example::
312-
313-
- name: runAdminCommand
314-
object: testRunner
315-
command_name: replSetFreeze
316-
arguments:
317-
command:
318-
replSetFreeze: 0
319-
readPreference:
320-
mode: Secondary
321-
322-
waitForPrimaryChange
323-
''''''''''''''''''''
324-
325-
The "waitForPrimaryChange" operation instructs the test runner to wait up to
326-
"timeoutMS" milliseconds for the MongoClient to discover a new primary server.
327-
The new primary should be different from the one recorded by "recordPrimary".
328-
For example::
329-
330-
- name: waitForPrimaryChange
331-
object: testRunner
332-
arguments:
333-
timeoutMS: 15000
334-
335-
To implement, Drivers can subscribe to ServerDescriptionChangedEvents and wait
336-
for an event where newDescription.type is ``RSPrimary`` and the address is
337-
different from the one previously recorded by "recordPrimary".
338-
339-
startThread
340-
'''''''''''
341-
342-
The "startThread" operation instructs the test runner to start a new thread
343-
with the provided "name". The `runOnThread`_ and `waitForThread`_ operations
344-
reference a thread by its "name". For example::
345-
346-
- name: startThread
347-
object: testRunner
348-
arguments:
349-
name: thread1
350-
351-
runOnThread
352-
'''''''''''
353-
354-
The "runOnThread" operation instructs the test runner to schedule an operation
355-
to be run on the given thread. runOnThread MUST NOT wait for the scheduled
356-
operation to complete. For example::
357-
358-
- name: runOnThread
359-
object: testRunner
360-
arguments:
361-
name: thread1
362-
operation:
363-
name: insertOne
364-
object: collection
365-
arguments:
366-
document:
367-
_id: 2
368-
error: true
369-
370-
waitForThread
371-
'''''''''''''
372-
373-
The "waitForThread" operation instructs the test runner to stop the given
374-
thread, wait for it to complete, and assert that the thread exited without
375-
any errors. For example::
376-
377-
- name: waitForThread
378-
object: testRunner
379-
arguments:
380-
name: thread1
191+
Integration tests are provided in the "unified" directory and are
192+
written in the `Unified Test Format
193+
<../unified-test-format/unified-test-format.rst>`_.
381194

382195
Prose Tests
383196
-----------

0 commit comments

Comments
 (0)