Skip to content

Commit 1f1f7e9

Browse files
CSHARP-2382: Resync read write concern tests to add new read concern levels.
1 parent 79faa5f commit 1f1f7e9

File tree

10 files changed

+132
-158
lines changed

10 files changed

+132
-158
lines changed

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

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,25 @@
1414
*/
1515

1616
using System;
17-
using System.Collections.Generic;
18-
using System.IO;
19-
using System.Linq;
20-
using System.Net;
21-
using System.Net.Sockets;
22-
using System.Reflection;
2317
using FluentAssertions;
2418
using MongoDB.Bson;
2519
using MongoDB.Driver.Core.Configuration;
26-
using MongoDB.Driver.Core.Misc;
2720
using Xunit;
28-
using Xunit.Sdk;
2921
using MongoDB.Bson.TestHelpers.XunitExtensions;
30-
using System.Collections;
22+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
3123

3224
namespace MongoDB.Driver.Specifications.read_write_concern.tests
3325
{
3426
public class ConnectionStringTestRunner
3527
{
3628
[Theory]
3729
[ClassData(typeof(TestCaseFactory))]
38-
public void RunTestDefinition(BsonDocument definition)
30+
public void RunTestDefinition(JsonDrivenTestCase testCase)
3931
{
32+
var definition = testCase.Test;
33+
34+
JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "description", "uri", "valid", "warning", "readConcern", "writeConcern");
35+
4036
ConnectionString connectionString = null;
4137
Exception parseException = null;
4238
try
@@ -111,59 +107,9 @@ private BsonDocument MassageWriteConcernDocument(BsonDocument writeConcern)
111107
return writeConcern;
112108
}
113109

114-
private class TestCaseFactory : IEnumerable<object[]>
110+
private class TestCaseFactory : JsonDrivenTestCaseFactory
115111
{
116-
public IEnumerator<object[]> GetEnumerator()
117-
{
118-
const string prefix = "MongoDB.Driver.Core.Tests.Specifications.read_write_concern.tests.connection_string.";
119-
var executingAssembly = typeof(TestCaseFactory).GetTypeInfo().Assembly;
120-
var enumerable = executingAssembly
121-
.GetManifestResourceNames()
122-
.Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
123-
.SelectMany(path =>
124-
{
125-
var definition = ReadDefinition(path);
126-
var tests = (BsonArray)definition["tests"];
127-
var fullName = path.Remove(0, prefix.Length);
128-
var list = new List<object[]>();
129-
foreach (BsonDocument test in tests)
130-
{
131-
//var data = new TestCaseData(test);
132-
//data.SetCategory("Specifications");
133-
//if (test.Contains("readConcern"))
134-
//{
135-
// data.SetCategory("ReadConcern");
136-
//}
137-
//else
138-
//{
139-
// data.SetCategory("WriteConcern");
140-
//}
141-
//data.SetCategory("ConnectionString");
142-
//var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"];
143-
//data = data.SetName(testName);
144-
var data = new object[] { test };
145-
list.Add(data);
146-
}
147-
return list;
148-
});
149-
return enumerable.GetEnumerator();
150-
}
151-
152-
IEnumerator IEnumerable.GetEnumerator()
153-
{
154-
return GetEnumerator();
155-
}
156-
157-
private static BsonDocument ReadDefinition(string path)
158-
{
159-
var executingAssembly = typeof(TestCaseFactory).GetTypeInfo().Assembly;
160-
using (var definitionStream = executingAssembly.GetManifestResourceStream(path))
161-
using (var definitionStringReader = new StreamReader(definitionStream))
162-
{
163-
var definitionString = definitionStringReader.ReadToEnd();
164-
return BsonDocument.Parse(definitionString);
165-
}
166-
}
112+
protected override string PathPrefix => "MongoDB.Driver.Core.Tests.Specifications.read_write_concern.tests.connection_string.";
167113
}
168114
}
169115
}

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

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,24 @@
1414
*/
1515

1616
using System;
17-
using System.Collections.Generic;
18-
using System.IO;
19-
using System.Linq;
20-
using System.Net;
21-
using System.Net.Sockets;
22-
using System.Reflection;
2317
using FluentAssertions;
2418
using MongoDB.Bson;
25-
using MongoDB.Driver.Core.Configuration;
26-
using MongoDB.Driver.Core.Misc;
2719
using Xunit;
28-
using Xunit.Sdk;
2920
using MongoDB.Bson.TestHelpers.XunitExtensions;
30-
using System.Collections;
21+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
3122

3223
namespace MongoDB.Driver.Specifications.read_write_concern.tests
3324
{
3425
public class DocumentTestRunner
3526
{
3627
[Theory]
3728
[ClassData(typeof(TestCaseFactory))]
38-
public void RunTestDefinition(BsonDocument definition)
29+
public void RunTestDefinition(JsonDrivenTestCase testCase)
3930
{
31+
var definition = testCase.Test;
32+
33+
JsonDrivenHelper.EnsureAllFieldsAreValid(definition, "description", "valid", "readConcern", "readConcernDocument", "isServerDefault", "writeConcern", "writeConcernDocument", "isAcknowledged");
34+
4035
BsonValue readConcernValue;
4136
if (definition.TryGetValue("readConcern", out readConcernValue))
4237
{
@@ -138,58 +133,9 @@ private BsonDocument MassageWriteConcernDocument(BsonDocument writeConcern)
138133
return writeConcern;
139134
}
140135

141-
private class TestCaseFactory : IEnumerable<object[]>
136+
private class TestCaseFactory : JsonDrivenTestCaseFactory
142137
{
143-
public IEnumerator<object[]> GetEnumerator()
144-
{
145-
const string prefix = "MongoDB.Driver.Core.Tests.Specifications.read_write_concern.tests.document.";
146-
var executingAssembly = typeof(TestCaseFactory).GetTypeInfo().Assembly;
147-
var enumerable = executingAssembly
148-
.GetManifestResourceNames()
149-
.Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
150-
.SelectMany(path =>
151-
{
152-
var definition = ReadDefinition(path);
153-
var tests = (BsonArray)definition["tests"];
154-
var fullName = path.Remove(0, prefix.Length);
155-
var list = new List<object[]>();
156-
foreach (BsonDocument test in tests)
157-
{
158-
//var data = new TestCaseData(test);
159-
//data.SetCategory("Specifications");
160-
//if (test.Contains("readConcern"))
161-
//{
162-
// data.SetCategory("ReadConcern");
163-
//}
164-
//else
165-
//{
166-
// data.SetCategory("WriteConcern");
167-
//}
168-
//var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"];
169-
//data = data.SetName(testName);
170-
var data = new object[] { test };
171-
list.Add(data);
172-
}
173-
return list;
174-
});
175-
return enumerable.GetEnumerator();
176-
}
177-
178-
IEnumerator IEnumerable.GetEnumerator()
179-
{
180-
return GetEnumerator();
181-
}
182-
183-
private static BsonDocument ReadDefinition(string path)
184-
{
185-
var executingAssembly = typeof(TestCaseFactory).GetTypeInfo().Assembly;
186-
using (var definitionStream = executingAssembly.GetManifestResourceStream(path))
187-
using (var definitionStringReader = new StreamReader(definitionStream))
188-
{
189-
var definitionString = definitionStringReader.ReadToEnd();
190-
return BsonDocument.Parse(definitionString);
191-
}
192-
}
138+
protected override string PathPrefix => "MongoDB.Driver.Core.Tests.Specifications.read_write_concern.tests.document.";
193139
}
194140
}
195141
}
Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
{
2-
"tests": [
3-
{
4-
"description": "Default",
5-
"uri": "mongodb://localhost/",
6-
"valid": true,
7-
"warning": false,
8-
"readConcern": { }
9-
},
10-
{
11-
"description": "local specified",
12-
"uri": "mongodb://localhost/?readConcernLevel=local",
13-
"valid": true,
14-
"warning": false,
15-
"readConcern": {
16-
"level": "local"
17-
}
18-
},
19-
{
20-
"description": "majority specified",
21-
"uri": "mongodb://localhost/?readConcernLevel=majority",
22-
"valid": true,
23-
"warning": false,
24-
"readConcern": {
25-
"level": "majority"
26-
}
27-
}
28-
]
29-
}
2+
"tests": [
3+
{
4+
"description": "Default",
5+
"uri": "mongodb://localhost/",
6+
"valid": true,
7+
"warning": false,
8+
"readConcern": {}
9+
},
10+
{
11+
"description": "local specified",
12+
"uri": "mongodb://localhost/?readConcernLevel=local",
13+
"valid": true,
14+
"warning": false,
15+
"readConcern": {
16+
"level": "local"
17+
}
18+
},
19+
{
20+
"description": "majority specified",
21+
"uri": "mongodb://localhost/?readConcernLevel=majority",
22+
"valid": true,
23+
"warning": false,
24+
"readConcern": {
25+
"level": "majority"
26+
}
27+
},
28+
{
29+
"description": "linearizable specified",
30+
"uri": "mongodb://localhost/?readConcernLevel=linearizable",
31+
"valid": true,
32+
"warning": false,
33+
"readConcern": {
34+
"level": "linearizable"
35+
}
36+
},
37+
{
38+
"description": "available specified",
39+
"uri": "mongodb://localhost/?readConcernLevel=available",
40+
"valid": true,
41+
"warning": false,
42+
"readConcern": {
43+
"level": "available"
44+
}
45+
}
46+
]
47+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ tests:
1717
valid: true
1818
warning: false
1919
readConcern: { level: "majority" }
20+
-
21+
description: "linearizable specified"
22+
uri: "mongodb://localhost/?readConcernLevel=linearizable"
23+
valid: true
24+
warning: false
25+
readConcern: { level: "linearizable" }
26+
-
27+
description: "available specified"
28+
uri: "mongodb://localhost/?readConcernLevel=available"
29+
valid: true
30+
warning: false
31+
readConcern: { level: "available" }
32+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@
115115
}
116116
}
117117
]
118-
}
118+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ tests:
7474
uri: "mongodb://localhost/?w=0&journal=true"
7575
valid: false
7676
warning: false
77-
writeConcern: { w: 0, journal: true }
77+
writeConcern: { w: 0, journal: true }

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@
2828
"level": "local"
2929
},
3030
"isServerDefault": false
31+
},
32+
{
33+
"description": "Linearizable",
34+
"valid": true,
35+
"readConcern": {
36+
"level": "linearizable"
37+
},
38+
"readConcernDocument": {
39+
"level": "linearizable"
40+
},
41+
"isServerDefault": false
42+
},
43+
{
44+
"description": "Snapshot",
45+
"valid": true,
46+
"readConcern": {
47+
"level": "snapshot"
48+
},
49+
"readConcernDocument": {
50+
"level": "snapshot"
51+
},
52+
"isServerDefault": false
53+
},
54+
{
55+
"description": "Available",
56+
"valid": true,
57+
"readConcern": {
58+
"level": "available"
59+
},
60+
"readConcernDocument": {
61+
"level": "available"
62+
},
63+
"isServerDefault": false
3164
}
3265
]
33-
}
66+
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,22 @@ tests:
1616
valid: true
1717
readConcern: { level: "local" }
1818
readConcernDocument: { level: "local" }
19-
isServerDefault: false
19+
isServerDefault: false
20+
-
21+
description: "Linearizable"
22+
valid: true
23+
readConcern: { level: "linearizable" }
24+
readConcernDocument: { level: "linearizable" }
25+
isServerDefault: false
26+
-
27+
description: "Snapshot"
28+
valid: true
29+
readConcern: { level: "snapshot" }
30+
readConcernDocument: {level: "snapshot" }
31+
isServerDefault: false
32+
-
33+
description: "Available"
34+
valid: true
35+
readConcern: { level: "available" }
36+
readConcernDocument: { level: "available" }
37+
isServerDefault: false

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
@@ -171,4 +171,4 @@
171171
"isAcknowledged": true
172172
}
173173
]
174-
}
174+
}

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
@@ -96,4 +96,4 @@ tests:
9696
writeConcern: { w: 3, wtimeoutMS: 1000, journal: true }
9797
writeConcernDocument: { w: 3, wtimeout: 1000, j: true }
9898
isServerDefault: false
99-
isAcknowledged: true
99+
isAcknowledged: true

0 commit comments

Comments
 (0)