Skip to content

Commit bf12ff8

Browse files
RUST-1186 Convert sessions tests to unified test format (#583)
1 parent 96b3a14 commit bf12ff8

19 files changed

+1728
-1392
lines changed

src/client/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ impl Client {
250250
}
251251

252252
/// Starts a new `ClientSession`.
253-
pub async fn start_session(&self, options: Option<SessionOptions>) -> Result<ClientSession> {
253+
pub async fn start_session(
254+
&self,
255+
options: impl Into<Option<SessionOptions>>,
256+
) -> Result<ClientSession> {
257+
let options = options.into();
254258
if let Some(ref options) = options {
255259
options.validate()?;
256260
}

src/test/spec/json/sessions/README.rst

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,14 @@ Driver Session Tests
99
Introduction
1010
============
1111

12-
The YAML and JSON files in the ``legacy`` and ``unified`` sub-directories are platform-independent tests
13-
that drivers can use to prove their conformance to the Driver Sessions Spec. They are
14-
designed with the intention of sharing most test-runner code with the
15-
`Transactions Spec tests <../../transactions/tests/README.rst#test-format>`_.. Tests in the
16-
``unified`` directory are written using the `Unified Test Format <../../unified-test-format/unified-test-format.rst>`_.
12+
The YAML and JSON files in this directory are platform-independent tests
13+
meant to exercise a driver's implementation of sessions. These tests utilize the
14+
`Unified Test Format <../../unified-test-format/unified-test-format.rst>`__.
1715

1816
Several prose tests, which are not easily expressed in YAML, are also presented
1917
in the Driver Sessions Spec. Those tests will need to be manually implemented
2018
by each driver.
2119

22-
Test Format
23-
===========
24-
25-
The same as the `Transactions Spec Test format
26-
<../../transactions/tests/README.rst#test-format>`_.
27-
28-
Special Test Operations
29-
```````````````````````
30-
31-
Certain operations that appear in the "operations" array do not correspond to
32-
API methods but instead represent special test operations. Such operations are
33-
defined on the "testRunner" object and are documented in the
34-
`Transactions Spec Test
35-
<../../transactions/tests/README.rst#special-test-operations>`_.
36-
Additional, session test specific operations are documented here:
37-
38-
assertDifferentLsidOnLastTwoCommands
39-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40-
41-
The "assertDifferentLsidOnLastTwoCommands" operation instructs the test runner
42-
to assert that the last two command started events from the test's MongoClient
43-
have different "lsid" fields. This assertion is used to ensure that dirty
44-
server sessions are discarded from the pool::
45-
46-
- name: assertDifferentLsidOnLastTwoCommands
47-
object: testRunner
48-
49-
assertSameLsidOnLastTwoCommands
50-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51-
52-
The "assertSameLsidOnLastTwoCommands" operation instructs the test runner
53-
to assert that the last two command started events from the test's MongoClient
54-
have the same "lsid" field. This assertion is used to ensure that non-dirty
55-
server sessions are not discarded from the pool::
56-
57-
- name: assertSameLsidOnLastTwoCommands
58-
object: testRunner
59-
60-
assertSessionDirty
61-
~~~~~~~~~~~~~~~~~~
62-
63-
The "assertSessionDirty" operation instructs the test runner to assert that
64-
the given session is marked dirty::
65-
66-
- name: assertSessionDirty
67-
object: testRunner
68-
arguments:
69-
session: session0
70-
71-
assertSessionNotDirty
72-
~~~~~~~~~~~~~~~~~~~~~
73-
74-
The "assertSessionNotDirty" operation instructs the test runner to assert that
75-
the given session is *not* marked dirty::
76-
77-
- name: assertSessionNotDirty
78-
object: testRunner
79-
arguments:
80-
session: session0
81-
8220
Snapshot session tests
8321
======================
8422
Snapshot sessions tests require server of version 5.0 or higher and
@@ -92,13 +30,17 @@ may lead to `SnapshotTooOld` errors. Drivers can work around this issue by incre
9230
9331
Prose tests
9432
```````````
95-
- Setting both ``snapshot`` and ``causalConsistency`` is not allowed
9633

97-
* ``client.startSession(snapshot = true, causalConsistency = true)``
98-
* Assert that an error was raised by driver
34+
1. Setting both ``snapshot`` and ``causalConsistency`` to true is not allowed
35+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36+
37+
* ``client.startSession(snapshot = true, causalConsistency = true)``
38+
* Assert that an error was raised by driver
9939

10040
Changelog
10141
=========
10242

10343
:2019-05-15: Initial version.
10444
:2021-06-15: Added snapshot-session tests. Introduced legacy and unified folders.
45+
:2021-07-30: Use numbering for prose test
46+
:2022-02-11: Convert legacy tests to unified format

0 commit comments

Comments
 (0)