Skip to content

Commit ec182f7

Browse files
committed
CSHARP-2170: Resync tests to update handling of inconsistent write concern
1 parent 00a43a1 commit ec182f7

File tree

9 files changed

+54
-51
lines changed

9 files changed

+54
-51
lines changed

src/MongoDB.Driver.Core/Core/Configuration/ConnectionString.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ private void Parse()
782782
ExtractDatabaseName(match);
783783
ExtractOptions(match);
784784
ExtractHosts(match);
785+
786+
if (_journal.HasValue && _journal.Value && _w != null && _w.Equals(0))
787+
{
788+
throw new MongoConfigurationException("This is an invalid w and journal pair.");
789+
}
785790
}
786791

787792
private void ParseOption(string name, string value)

src/MongoDB.Driver.Core/WriteConcern.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public WriteConcern(
195195
_wTimeout = Ensure.IsNullOrGreaterThanZero(wTimeout.WithDefault(null), "wTimeout");
196196
_fsync = fsync.WithDefault(null);
197197
_journal = journal.WithDefault(null);
198+
199+
if (_w != null && w.Value.Equals(0) && _journal.HasValue && journal.Value.Equals(true))
200+
{
201+
throw new MongoConfigurationException("This write concern is not valid.");
202+
}
198203
}
199204

200205
// properties

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/ConnectionStringTestRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ private void AssertValid(ConnectionString connectionString, BsonDocument definit
7676
BsonValue writeConcernValue;
7777
if (definition.TryGetValue("writeConcern", out writeConcernValue))
7878
{
79-
var writeConcern = WriteConcern.FromBsonDocument(MassageWriteConcernDocument((BsonDocument)writeConcernValue));
80-
79+
var writeConcern =
80+
WriteConcern.FromBsonDocument(MassageWriteConcernDocument((BsonDocument) writeConcernValue));
8181
connectionString.W.Should().Be(writeConcern.W);
8282
connectionString.WTimeout.Should().Be(writeConcern.WTimeout);
8383
connectionString.Journal.Should().Be(writeConcern.Journal);

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/tests/README.rst

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,51 @@ The YAML and JSON files in this directory tree are platform-independent tests
66
that drivers can use to prove their conformance to the Read and Write Concern
77
specification.
88

9-
Converting to JSON
10-
------------------
11-
12-
The tests are written in YAML because it is easier for humans to write and read,
13-
and because YAML includes a standard comment format. A JSONified version of each
14-
YAML file is included in this repository. Whenever you change the YAML,
15-
re-convert to JSON. One method to convert to JSON is with
16-
`jsonwidget-python <http://jsonwidget.org/wiki/Jsonwidget-python>`_::
17-
18-
pip install PyYAML urwid jsonwidget
19-
make
20-
21-
Or instead of "make"::
22-
23-
for i in `find . -iname '*.yml'`; do
24-
echo "${i%.*}"
25-
jwc yaml2json $i > ${i%.*}.json
26-
done
27-
28-
Alternatively, you can use `yamljs <https://www.npmjs.com/package/yamljs>`_::
29-
30-
npm install -g yamljs
31-
yaml2json -s -p -r .
32-
339
Version
3410
-------
3511

3612
Files in the "specifications" repository have no version scheme. They are not
37-
tied to a MongoDB server version, and it is our intention that each
38-
specification moves from "draft" to "final" with no further versions; it is
39-
superseded by a future spec, not revised.
40-
41-
However, implementers must have stable sets of tests to target. As test files
42-
evolve they will be occasionally tagged like "uri-tests-tests-2015-07-16", until
43-
the spec is final.
13+
tied to a MongoDB server version.
4414

4515
Format
4616
------
4717

18+
Connection String
19+
~~~~~~~~~~~~~~~~~
20+
21+
These tests are designed to exercise the connection string parsing related
22+
to read concern and write concern.
23+
4824
Each YAML file contains an object with a single ``tests`` key. This key is an
4925
array of test case objects, each of which have the following keys:
5026

5127
- ``description``: A string describing the test.
5228
- ``uri``: A string containing the URI to be parsed.
29+
- ``valid:``: a boolean indicating if parsing the uri should result in an error.
5330
- ``writeConcern:`` A document indicating the expected write concern.
54-
- ``isAcknowledged:`` A boolean indicating whether the write concern is
55-
acknowledged.
5631
- ``readConcern:`` A document indicating the expected read concern.
57-
- ``error:``: a boolean indicating if parsing the uri should result in an error, or the string
58-
'optional' indicating that reporting of an error is optional
5932

60-
If a test case includes a null value for one of these keys,
61-
no assertion is necessary. This both simplifies parsing of the
62-
test files (keys should always exist) and allows flexibility for drivers that
63-
might substitute default values *during* parsing.
33+
If a test case includes a null value for one of these keys, or if the key is missing,
34+
no assertion is necessary. This both simplifies parsing of the test files and allows flexibility
35+
for drivers that might substitute default values *during* parsing.
36+
37+
Document
38+
~~~~~~~~
39+
40+
These tests are designed to ensure compliance with the spec in relation to what should be
41+
sent to the server.
42+
43+
Each YAML file contains an object with a single ``tests`` key. This key is an
44+
array of test case objects, each of which have the following keys:
45+
46+
- ``description``: A string describing the test.
47+
- ``valid:``: a boolean indicating if the write concern created from the document is valid.
48+
- ``writeConcern:`` A document indicating the write concern to use.
49+
- ``writeConcernDocument:`` A document indicating the write concern to be sent to the server.
50+
- ``readConcern:`` A document indicating the read concern to use.
51+
- ``readConcernDocument:`` A document indicating the read concern to be sent to the server.
52+
- ``isServerDefault:`` Indicates whether the read or write concern is considered the server's default.
53+
- ``isAcknowledged:`` Indicates if the write concern should be considered acknowledged.
6454

6555
Use as unit tests
6656
=================

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/tests/connection-string/write-concern.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
{
108108
"description": "Acknowledged with w as 0 and journal true",
109109
"uri": "mongodb://localhost/?w=0&journal=true",
110-
"valid": true,
111-
"warning": true,
110+
"valid": false,
111+
"warning": false,
112112
"writeConcern": {
113113
"w": 0,
114114
"journal": true

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/tests/connection-string/write-concern.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ tests:
7272
-
7373
description: "Acknowledged with w as 0 and journal true"
7474
uri: "mongodb://localhost/?w=0&journal=true"
75-
valid: true
76-
warning: true
75+
valid: false
76+
warning: false
7777
writeConcern: { w: 0, journal: true }

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/tests/document/write-concern.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
},
143143
{
144144
"description": "W is 0 with journal true",
145-
"valid": true,
145+
"valid": false,
146146
"writeConcern": {
147147
"w": 0,
148148
"journal": true

tests/MongoDB.Driver.Core.Tests/Specifications/read-write-concern/tests/document/write-concern.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ tests:
8585
isAcknowledged: false
8686
-
8787
description: "W is 0 with journal true"
88-
valid: true
88+
valid: false
8989
writeConcern: { w: 0, journal: true }
9090
writeConcernDocument: { w: 0, j: true }
9191
isServerDefault: false

tests/MongoDB.Driver.Core.Tests/WriteConcernTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,15 @@ public void constructor_with_w_and_fsync_should_initialize_instance(
193193
result.WTimeout.Should().NotHaveValue();
194194
}
195195

196+
// exclude case where w = 0 and journal = true per new spec
196197
[Theory]
197-
[ParameterAttributeData]
198+
[InlineData(0, null)]
199+
[InlineData(1, null)]
200+
[InlineData(0, false)]
201+
[InlineData(1, true)]
202+
[InlineData(1, false)]
198203
public void constructor_with_w_and_journal_should_initialize_instance(
199-
[Values(0, 1)]
200204
int w,
201-
[Values(false, true, null)]
202205
bool? journal)
203206
{
204207
var result = new WriteConcern(w, journal: journal);
@@ -333,13 +336,13 @@ public void Equals_should_return_true_when_all_fields_are_equal()
333336
hashCode1.Should().Be(hashCode2);
334337
}
335338

339+
// exclude w = 0 and journal = true per new spec
336340
[Theory]
337341
[InlineData(0, null, null, null, false)]
338342
[InlineData(1, null, null, null, true)]
339343
[InlineData(0, false, null, null, false)]
340344
[InlineData(0, true, null, null, true)]
341345
[InlineData(0, null, false, null, false)]
342-
[InlineData(0, null, true, null, true)]
343346
[InlineData(0, null, null, 1, false)]
344347
public void IsAcknowledged_should_return_expected_result_with_w(
345348
int? w,

0 commit comments

Comments
 (0)