Skip to content

Commit 1b34bfe

Browse files
committed
CSHARP-4400: Upgrade xunit to 2.4.2 and remove SkippableFact package
1 parent 8f203d7 commit 1b34bfe

File tree

190 files changed

+1135
-1129
lines changed

Some content is hidden

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

190 files changed

+1135
-1129
lines changed

CSharpDriver.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
5454
MongoDBTest.ruleset = MongoDBTest.ruleset
5555
EndProjectSection
5656
EndProject
57-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkippableTests", "tests\SkippableTests\SkippableTests.csproj", "{D198833A-6AC3-4327-8B02-5095455192D0}"
58-
EndProject
5957
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Driver.TestConsoleApplication", "tests\MongoDB.Driver.TestConsoleApplication\MongoDB.Driver.TestConsoleApplication.csproj", "{2E5780D2-29A5-483C-9CA2-844F45A66D0C}"
6058
EndProject
6159
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AstrolabeWorkloadExecutor", "tests\AstrolabeWorkloadExecutor\AstrolabeWorkloadExecutor.csproj", "{B90F025F-89D3-436A-AD78-6AA304A6E240}"
@@ -134,10 +132,6 @@ Global
134132
{7A015030-6329-4FAD-B6E3-CED5ED53019C}.Debug|Any CPU.Build.0 = Debug|Any CPU
135133
{7A015030-6329-4FAD-B6E3-CED5ED53019C}.Release|Any CPU.ActiveCfg = Release|Any CPU
136134
{7A015030-6329-4FAD-B6E3-CED5ED53019C}.Release|Any CPU.Build.0 = Release|Any CPU
137-
{D198833A-6AC3-4327-8B02-5095455192D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
138-
{D198833A-6AC3-4327-8B02-5095455192D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
139-
{D198833A-6AC3-4327-8B02-5095455192D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
140-
{D198833A-6AC3-4327-8B02-5095455192D0}.Release|Any CPU.Build.0 = Release|Any CPU
141135
{2E5780D2-29A5-483C-9CA2-844F45A66D0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
142136
{2E5780D2-29A5-483C-9CA2-844F45A66D0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
143137
{2E5780D2-29A5-483C-9CA2-844F45A66D0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -171,7 +165,6 @@ Global
171165
{C50D554C-2771-4CC1-9B2C-BB17FB27F935} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
172166
{DAB8DFFD-0020-43B3-9C08-7723F5D68E90} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
173167
{7A015030-6329-4FAD-B6E3-CED5ED53019C} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
174-
{D198833A-6AC3-4327-8B02-5095455192D0} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
175168
{2E5780D2-29A5-483C-9CA2-844F45A66D0C} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
176169
{B90F025F-89D3-436A-AD78-6AA304A6E240} = {E472BDF5-61F1-461D-872B-9F53BB3ACA80}
177170
{B711A69F-A337-452C-95E1-A6B15C727CBA} = {F64BF86A-1EF1-4596-84A6-6B4AB766CD77}

tests/MongoDB.Bson.TestHelpers/XunitExtensions/RequireEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
using System.Diagnostics;
1818
using System.Net;
1919
using System.Net.Sockets;
20-
using Xunit;
20+
using Xunit.Sdk;
2121

2222
namespace MongoDB.Bson.TestHelpers.XunitExtensions
2323
{

tests/MongoDB.Bson.TestHelpers/XunitExtensions/RequireProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
using System;
17-
using Xunit;
17+
using Xunit.Sdk;
1818

1919
namespace MongoDB.Bson.TestHelpers.XunitExtensions
2020
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Copyright 2010-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;
17+
18+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
19+
{
20+
public interface ITestExceptionHandler
21+
{
22+
void HandleException(Exception ex);
23+
}
24+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* Copyright 2010-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;
17+
using System.Linq;
18+
using Xunit.Abstractions;
19+
using Xunit.Sdk;
20+
21+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
22+
{
23+
internal sealed class SkippableTestMessageBus : IMessageBus
24+
{
25+
private readonly static string __skippableExceptionName = typeof(SkipException).FullName;
26+
27+
private readonly IMessageBus _messageBus;
28+
private int _skippedCount;
29+
30+
public SkippableTestMessageBus(IMessageBus messageBus)
31+
{
32+
if (messageBus == null)
33+
{
34+
throw new ArgumentNullException(nameof(messageBus));
35+
}
36+
37+
_messageBus = messageBus;
38+
}
39+
40+
public int SkippedCount => _skippedCount;
41+
42+
public void Dispose()
43+
{
44+
_messageBus.Dispose();
45+
}
46+
47+
/// <inheritdoc />
48+
public bool QueueMessage(IMessageSinkMessage message)
49+
{
50+
var failed = message as TestFailed;
51+
if (message is TestFailed testFailed &&
52+
testFailed.ExceptionTypes.FirstOrDefault() == __skippableExceptionName)
53+
{
54+
_skippedCount++;
55+
return _messageBus.QueueMessage(new TestSkipped(failed.Test, failed.Messages[0]));
56+
}
57+
58+
return _messageBus.QueueMessage(message);
59+
}
60+
}
61+
}
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -17,18 +17,46 @@
1717
using System.Collections.Generic;
1818
using System.Diagnostics;
1919
using System.Reflection;
20+
using System.Runtime.CompilerServices;
2021
using System.Threading;
2122
using System.Threading.Tasks;
22-
using MongoDB.Driver.Core.TestHelpers.Logging;
23-
using Xunit;
2423
using Xunit.Abstractions;
2524
using Xunit.Sdk;
2625

27-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
26+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2827
{
2928
[DebuggerStepThrough]
3029
internal sealed class TimeoutEnforcingTestInvoker : XunitTestInvoker
3130
{
31+
// This is a copy of MongoDB.Driver.Core.Misc.TaskExtensions.YieldNoContextAwaitable struct
32+
// Remove this copy when moving TaskExtensions to BSON level.
33+
private struct YieldNoContextAwaitable
34+
{
35+
public YieldNoContextAwaiter GetAwaiter() { return new YieldNoContextAwaiter(); }
36+
37+
public struct YieldNoContextAwaiter : ICriticalNotifyCompletion
38+
{
39+
/// <summary>Gets whether a yield is not required.</summary>
40+
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
41+
public bool IsCompleted { get { return false; } } // yielding is always required for YieldNoContextAwaiter, hence false
42+
43+
public void OnCompleted(Action continuation)
44+
{
45+
Task.Factory.StartNew(continuation, default, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
46+
}
47+
48+
public void UnsafeOnCompleted(Action continuation)
49+
{
50+
Task.Factory.StartNew(continuation, default, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
51+
}
52+
53+
public void GetResult()
54+
{
55+
// no op
56+
}
57+
}
58+
}
59+
3260
public TimeoutEnforcingTestInvoker(
3361
ITest test,
3462
IMessageBus messageBus,
@@ -45,7 +73,7 @@ public TimeoutEnforcingTestInvoker(
4573

4674
private async Task<decimal> InvokeBaseOnTaskScheduler(object testClassInstance)
4775
{
48-
await Misc.TaskExtensions.YieldNoContext();
76+
await new YieldNoContextAwaitable();
4977

5078
return await base.InvokeTestMethodAsync(testClassInstance);
5179
}
@@ -56,10 +84,10 @@ protected override async Task<decimal> InvokeTestMethodAsync(object testClassIns
5684
var timeoutMS = xUnitTestCase?.Timeout ?? 0;
5785
var timeout = Debugger.IsAttached
5886
? Timeout.InfiniteTimeSpan // allow more flexible debugging expirience
59-
: timeoutMS <= 0 ? CoreTestConfiguration.DefaultTestTimeout : TimeSpan.FromMilliseconds(timeoutMS);
87+
: timeoutMS <= 0 ? XunitExtensionsConstants.DefaultTestTimeout : TimeSpan.FromMilliseconds(timeoutMS);
6088

6189

62-
var testLoggable = testClassInstance as LoggableTestClass;
90+
var testExceptionHandler = testClassInstance as ITestExceptionHandler;
6391

6492
decimal result;
6593
try
@@ -72,21 +100,21 @@ protected override async Task<decimal> InvokeTestMethodAsync(object testClassIns
72100
throw new TestTimeoutException((int)timeout.TotalMilliseconds);
73101
}
74102

75-
if (Aggregator.HasExceptions && testLoggable != null)
103+
if (Aggregator.HasExceptions && testExceptionHandler != null)
76104
{
77105
var exception = Aggregator.ToException();
78106

79107
if (exception is not SkipException)
80108
{
81-
testLoggable.OnException(exception);
109+
testExceptionHandler.HandleException(exception);
82110
}
83111
}
84112

85113
result = await baseTask;
86114
}
87115
catch (Exception exception)
88116
{
89-
testLoggable?.OnException(exception);
117+
testExceptionHandler?.HandleException(exception);
90118

91119
throw;
92120
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -22,7 +22,7 @@
2222
using Xunit.Abstractions;
2323
using Xunit.Sdk;
2424

25-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
25+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2626
{
2727
[DebuggerStepThrough]
2828
internal sealed class TimeoutEnforcingTestRunner : XunitTestRunner
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -20,7 +20,7 @@
2020
using Xunit.Abstractions;
2121
using Xunit.Sdk;
2222

23-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
23+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2424
{
2525
[DebuggerStepThrough]
2626
internal sealed class TimeoutEnforcingXunitTestAssemblyRunner : XunitTestAssemblyRunner
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -21,7 +21,7 @@
2121
using Xunit.Abstractions;
2222
using Xunit.Sdk;
2323

24-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
24+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2525
{
2626
[DebuggerStepThrough]
2727
internal sealed class TimeoutEnforcingXunitTestCaseRunner : XunitTestCaseRunner
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -21,7 +21,7 @@
2121
using Xunit.Abstractions;
2222
using Xunit.Sdk;
2323

24-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
24+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2525
{
2626
[DebuggerStepThrough]
2727
internal sealed class TimeoutEnforcingXunitTestClassRunner : XunitTestClassRunner
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -20,7 +20,7 @@
2020
using Xunit.Abstractions;
2121
using Xunit.Sdk;
2222

23-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
23+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2424
{
2525
[DebuggerStepThrough]
2626
internal sealed class TimeoutEnforcingXunitTestCollectionRunner : XunitTestCollectionRunner
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -18,7 +18,7 @@
1818
using Xunit.Abstractions;
1919
using Xunit.Sdk;
2020

21-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
21+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2222
{
2323
[DebuggerStepThrough]
2424
public sealed class TimeoutEnforcingXunitTestFramework : XunitTestFramework
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -19,7 +19,7 @@
1919
using Xunit.Abstractions;
2020
using Xunit.Sdk;
2121

22-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
22+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2323
{
2424
[DebuggerStepThrough]
2525
internal sealed class TimeoutEnforcingXunitTestFrameworkExecutor : XunitTestFrameworkExecutor
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -17,17 +17,14 @@
1717
using System.Diagnostics;
1818
using System.Threading;
1919
using System.Threading.Tasks;
20-
using Xunit;
2120
using Xunit.Abstractions;
2221
using Xunit.Sdk;
2322

24-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
23+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2524
{
2625
[DebuggerStepThrough]
2726
internal sealed class TimeoutEnforcingXunitTestMethodRunner : XunitTestMethodRunner
2827
{
29-
private static string[] __skippingExceptionNames = new string[] { typeof(SkipException).FullName };
30-
3128
private readonly object[] _constructorArguments;
3229
private readonly IMessageSink _diagnosticMessageSink;
3330

@@ -39,7 +36,7 @@ public TimeoutEnforcingXunitTestMethodRunner(ITestMethod testMethod, IReflection
3936

4037
protected override async Task<RunSummary> RunTestCaseAsync(IXunitTestCase originalTestCase)
4138
{
42-
var messageBusInterceptor = new SkippableTestMessageBus(MessageBus, __skippingExceptionNames);
39+
var messageBusInterceptor = new SkippableTestMessageBus(MessageBus);
4340

4441
var isTheory = originalTestCase is XunitTheoryTestCase;
4542
XunitTestCaseRunner testRunner = isTheory ?
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021-present MongoDB Inc.
1+
/* Copyright 2010-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.
@@ -21,7 +21,7 @@
2121
using Xunit.Abstractions;
2222
using Xunit.Sdk;
2323

24-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
24+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2525
{
2626
[DebuggerStepThrough]
2727
internal sealed class TimeoutEnforcingXunitTheoryTestCaseRunner : XunitTheoryTestCaseRunner

0 commit comments

Comments
 (0)