Skip to content

Commit 2fd7d06

Browse files
CSHARP-3523: Split the unified test runner into 2 classes. (mongodb#511)
1 parent a890e5f commit 2fd7d06

File tree

10 files changed

+85
-63
lines changed

10 files changed

+85
-63
lines changed

tests/AstrolabeWorkloadExecutor/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
using MongoDB.Driver;
2525
using MongoDB.Driver.Core;
2626
using MongoDB.Driver.Core.Misc;
27-
using MongoDB.Driver.Tests.Specifications.unified_test_format;
2827
using MongoDB.Driver.Tests.UnifiedTestOperations;
2928

3029
namespace WorkloadExecutor
@@ -113,16 +112,16 @@ private static (string EventsJson, string ResultsJson) ExecuteWorkload(string co
113112
{
114113
{ "events", new AstrolabeEventFormatter() } // "events" matches to the "storeEventsAsEntities.id" in the driverWorkload document
115114
};
116-
using (var testRunner = new UnifiedTestFormatTestRunner(
115+
using (var runner = new UnifiedTestRunner(
117116
allowKillSessions: false,
118117
additionalArgs: additionalArgs,
119118
eventFormatters: eventFormatters))
120119
{
121120
var factory = new TestCaseFactory();
122121
var testCase = factory.CreateTestCase(driverWorkload, async);
123-
testRunner.Run(testCase);
122+
runner.Run(testCase);
124123
Console.WriteLine("dotnet ExecuteWorkload> Returning...");
125-
return CreateWorkloadResult(entityMap: testRunner.EntityMap);
124+
return CreateWorkloadResult(entityMap: runner.EntityMap);
126125
}
127126
}
128127

tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamUnifiedTestRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
using System.Collections.Generic;
1717
using MongoDB.Bson;
1818
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
19-
using MongoDB.Driver.Tests.Specifications.unified_test_format;
19+
using MongoDB.Driver.Tests.UnifiedTestOperations;
2020
using Xunit;
2121

22-
namespace MongoDB.Driver.Tests.Specifications.crud.Unified
22+
namespace MongoDB.Driver.Tests.Specifications.change_streams
2323
{
2424
public sealed class ChangeStreamUnifiedTestRunner
2525
{
2626
[SkippableTheory]
2727
[ClassData(typeof(TestCaseFactory))]
2828
public void Run(JsonDrivenTestCase testCase)
2929
{
30-
using (var runner = new UnifiedTestFormatTestRunner())
30+
using (var runner = new UnifiedTestRunner())
3131
{
3232
runner.Run(testCase);
3333
}

tests/MongoDB.Driver.Tests/Specifications/crud/CrudUnifiedTestRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Collections.Generic;
1717
using MongoDB.Bson;
1818
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
19-
using MongoDB.Driver.Tests.Specifications.unified_test_format;
19+
using MongoDB.Driver.Tests.UnifiedTestOperations;
2020
using Xunit;
2121

2222
namespace MongoDB.Driver.Tests.Specifications.crud
@@ -27,7 +27,7 @@ public sealed class CrudUnifiedTestRunner
2727
[ClassData(typeof(TestCaseFactory))]
2828
public void Run(JsonDrivenTestCase testCase)
2929
{
30-
using (var runner = new UnifiedTestFormatTestRunner())
30+
using (var runner = new UnifiedTestRunner())
3131
{
3232
runner.Run(testCase);
3333
}

tests/MongoDB.Driver.Tests/Specifications/unified-test-format/UnifiedTestFormatNegativeTestRunner.cs renamed to tests/MongoDB.Driver.Tests/Specifications/unified-test-format/UnifiedTestFormatValidFailTestRunner.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,26 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
1716
using System.Collections.Generic;
1817
using FluentAssertions;
1918
using MongoDB.Bson;
2019
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
20+
using MongoDB.Driver.Tests.UnifiedTestOperations;
2121
using Xunit;
2222

2323
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
2424
{
25-
public sealed class UnifiedTestFormatNegativeTestRunner : IDisposable
25+
public sealed class UnifiedTestFormatValidFailTestRunner
2626
{
27-
private readonly UnifiedTestFormatTestRunner _unifiedTestFormatTestRunner = new UnifiedTestFormatTestRunner();
28-
29-
public void Dispose()
30-
{
31-
_unifiedTestFormatTestRunner.Dispose();
32-
}
33-
3427
[Theory]
3528
[ClassData(typeof(TestCaseFactory))]
3629
public void Run(JsonDrivenTestCase testCase)
3730
{
38-
var exception = Record.Exception(() => _unifiedTestFormatTestRunner.Run(testCase));
39-
40-
exception.Should().NotBeNull();
31+
using (var runner = new UnifiedTestRunner())
32+
{
33+
var exception = Record.Exception(() => runner.Run(testCase));
34+
exception.Should().NotBeNull();
35+
}
4136
}
4237

4338
// nested types
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using MongoDB.Bson;
19+
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
20+
using MongoDB.Driver.Tests.UnifiedTestOperations;
21+
using Xunit;
22+
23+
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
24+
{
25+
public sealed class UnifiedTestFormatValidPassTestRunner
26+
{
27+
[SkippableTheory]
28+
[ClassData(typeof(TestCaseFactory))]
29+
public void Run(JsonDrivenTestCase testCase)
30+
{
31+
using (var runner = new UnifiedTestRunner())
32+
{
33+
runner.Run(testCase);
34+
}
35+
}
36+
37+
// nested types
38+
public class TestCaseFactory : JsonDrivenTestCaseFactory
39+
{
40+
// protected properties
41+
protected override string PathPrefix => "MongoDB.Driver.Tests.Specifications.unified_test_format.tests.valid_pass.";
42+
43+
// protected methods
44+
protected override IEnumerable<JsonDrivenTestCase> CreateTestCases(BsonDocument document)
45+
{
46+
var testCases = base.CreateTestCases(document);
47+
foreach (var testCase in testCases)
48+
{
49+
foreach (var async in new[] { false, true })
50+
{
51+
var name = $"{testCase.Name.Replace(PathPrefix, "")}:async={async}";
52+
var test = testCase.Test.DeepClone().AsBsonDocument.Add("async", async);
53+
yield return new JsonDrivenTestCase(name, testCase.Shared, test);
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}

tests/MongoDB.Driver.Tests/Specifications/versioned-api/VersionedApiUnifiedTestRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Collections.Generic;
1717
using MongoDB.Bson;
1818
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
19-
using MongoDB.Driver.Tests.Specifications.unified_test_format;
19+
using MongoDB.Driver.Tests.UnifiedTestOperations;
2020
using Xunit;
2121

2222
namespace MongoDB.Driver.Tests.Specifications.versioned_api
@@ -27,7 +27,7 @@ public sealed class VersionedApiUnifiedTestRunner
2727
[ClassData(typeof(TestCaseFactory))]
2828
public void Run(JsonDrivenTestCase testCase)
2929
{
30-
using (var runner = new UnifiedTestFormatTestRunner())
30+
using (var runner = new UnifiedTestRunner())
3131
{
3232
runner.Run(testCase);
3333
}

tests/MongoDB.Driver.Tests/Specifications/unified-test-format/UnifiedErrorMatcher.cs renamed to tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedErrorMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using MongoDB.Bson;
2121
using MongoDB.Bson.TestHelpers.XunitExtensions;
2222

23-
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
23+
namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
2424
{
2525
public class UnifiedErrorMatcher
2626
{

tests/MongoDB.Driver.Tests/Specifications/unified-test-format/UnifiedEventMatcher.cs renamed to tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedEventMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using MongoDB.Driver.Core.Events;
2323
using Xunit.Sdk;
2424

25-
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
25+
namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
2626
{
2727
public class UnifiedEventMatcher
2828
{

tests/MongoDB.Driver.Tests/Specifications/unified-test-format/UnifiedValueMatcher.cs renamed to tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedValueMatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
using MongoDB.Bson;
2121
using MongoDB.Bson.IO;
2222
using MongoDB.Bson.TestHelpers.XunitExtensions;
23-
using MongoDB.Driver.Tests.UnifiedTestOperations;
23+
using MongoDB.Driver;
2424
using Xunit.Sdk;
2525

26-
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
26+
namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
2727
{
2828
public class UnifiedValueMatcher
2929
{
Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2020-present MongoDB Inc.
1+
/* Copyright 2021-present MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@
2525
using MongoDB.Driver.Core.Misc;
2626
using MongoDB.Driver.Core.TestHelpers;
2727
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
28-
using MongoDB.Driver.Tests.UnifiedTestOperations;
28+
using MongoDB.Driver.Tests.UnifiedTestOperations.Matchers;
2929
using Xunit;
3030

31-
namespace MongoDB.Driver.Tests.Specifications.unified_test_format
31+
namespace MongoDB.Driver.Tests.UnifiedTestOperations
3232
{
33-
public sealed class UnifiedTestFormatTestRunner : IDisposable
33+
public sealed class UnifiedTestRunner : IDisposable
3434
{
3535
private readonly bool _allowKillSessions;
3636
private UnifiedEntityMap _entityMap;
@@ -39,7 +39,7 @@ public sealed class UnifiedTestFormatTestRunner : IDisposable
3939
private readonly Dictionary<string, IEventFormatter> _eventFormatters;
4040
private bool _runHasBeenCalled;
4141

42-
public UnifiedTestFormatTestRunner(
42+
public UnifiedTestRunner(
4343
bool allowKillSessions = true, // TODO: should be removed after SERVER-54216
4444
Dictionary<string, object> additionalArgs = null,
4545
Dictionary<string, IEventFormatter> eventFormatters = null)
@@ -52,8 +52,6 @@ public UnifiedTestFormatTestRunner(
5252
// public properties
5353
public UnifiedEntityMap EntityMap => _entityMap;
5454

55-
[SkippableTheory]
56-
[ClassData(typeof(TestCaseFactory))]
5755
public void Run(JsonDrivenTestCase testCase)
5856
{
5957
// Top-level fields
@@ -324,34 +322,5 @@ private void KillOpenTransactions(IMongoClient client)
324322
}
325323
}
326324
}
327-
328-
// nested types
329-
public class TestCaseFactory : JsonDrivenTestCaseFactory
330-
{
331-
#region static
332-
private static readonly string[] __ignoredTestNames =
333-
{
334-
"poc-retryable-writes.json:InsertOne fails after multiple retryable writeConcernErrors" // CSHARP-3269
335-
};
336-
#endregion
337-
338-
// protected properties
339-
protected override string PathPrefix => "MongoDB.Driver.Tests.Specifications.unified_test_format.tests.valid_pass.";
340-
341-
// protected methods
342-
protected override IEnumerable<JsonDrivenTestCase> CreateTestCases(BsonDocument document)
343-
{
344-
var testCases = base.CreateTestCases(document).Where(test => !__ignoredTestNames.Any(ignoredName => test.Name.EndsWith(ignoredName)));
345-
foreach (var testCase in testCases)
346-
{
347-
foreach (var async in new[] { false, true })
348-
{
349-
var name = $"{testCase.Name.Replace(PathPrefix, "")}:async={async}";
350-
var test = testCase.Test.DeepClone().AsBsonDocument.Add("async", async);
351-
yield return new JsonDrivenTestCase(name, testCase.Shared, test);
352-
}
353-
}
354-
}
355-
}
356325
}
357326
}

0 commit comments

Comments
 (0)