Skip to content

Commit 9fbd696

Browse files
committed
- TimeoutEnforcing runner moved to Bson.TestsHelpers
- XUnit.Fact removed from Bson
1 parent 858839f commit 9fbd696

37 files changed

+151
-81
lines changed

tests/MongoDB.Bson.TestHelpers/MongoDB.Bson.TestHelpers.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" />
3939
<PackageReference Include="xunit" Version="2.4.2" />
4040
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" />
41-
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13">
42-
<PrivateAssets>all</PrivateAssets>
43-
</PackageReference>
4441
</ItemGroup>
4542

4643
<ItemGroup>

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
4+
{
5+
public interface ITestExceptionHandler
6+
{
7+
void HandleException(Exception ex);
8+
}
9+
}
Lines changed: 9 additions & 4 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.
@@ -13,12 +13,12 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using System.Linq;
17-
using MongoDB.Driver.Core.Misc;
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
internal sealed class SkippableTestMessageBus : IMessageBus
2424
{
@@ -29,7 +29,12 @@ internal sealed class SkippableTestMessageBus : IMessageBus
2929

3030
public SkippableTestMessageBus(IMessageBus messageBus)
3131
{
32-
_messageBus = Ensure.IsNotNull(messageBus, nameof(messageBus));
32+
if (messageBus == null)
33+
{
34+
throw new ArgumentNullException(nameof(messageBus));
35+
}
36+
37+
_messageBus = messageBus;
3338
}
3439

3540
public int SkippedCount => _skippedCount;
Lines changed: 36 additions & 9 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,44 @@
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;
2323
using Xunit.Abstractions;
2424
using Xunit.Sdk;
2525

26-
namespace MongoDB.Driver.Core.TestHelpers.XunitExtensions.TimeoutEnforcing
26+
namespace MongoDB.Bson.TestHelpers.XunitExtensions.TimeoutEnforcing
2727
{
2828
[DebuggerStepThrough]
2929
internal sealed class TimeoutEnforcingTestInvoker : XunitTestInvoker
3030
{
31+
private struct YieldNoContextAwaitable
32+
{
33+
public YieldNoContextAwaiter GetAwaiter() { return new YieldNoContextAwaiter(); }
34+
35+
public struct YieldNoContextAwaiter : ICriticalNotifyCompletion
36+
{
37+
/// <summary>Gets whether a yield is not required.</summary>
38+
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
39+
public bool IsCompleted { get { return false; } } // yielding is always required for YieldNoContextAwaiter, hence false
40+
41+
public void OnCompleted(Action continuation)
42+
{
43+
Task.Factory.StartNew(continuation, default, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
44+
}
45+
46+
public void UnsafeOnCompleted(Action continuation)
47+
{
48+
Task.Factory.StartNew(continuation, default, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
49+
}
50+
51+
public void GetResult()
52+
{
53+
// no op
54+
}
55+
}
56+
}
57+
3158
public TimeoutEnforcingTestInvoker(
3259
ITest test,
3360
IMessageBus messageBus,
@@ -44,7 +71,7 @@ public TimeoutEnforcingTestInvoker(
4471

4572
private async Task<decimal> InvokeBaseOnTaskScheduler(object testClassInstance)
4673
{
47-
await Misc.TaskExtensions.YieldNoContext();
74+
await new YieldNoContextAwaitable();
4875

4976
return await base.InvokeTestMethodAsync(testClassInstance);
5077
}
@@ -55,10 +82,10 @@ protected override async Task<decimal> InvokeTestMethodAsync(object testClassIns
5582
var timeoutMS = xUnitTestCase?.Timeout ?? 0;
5683
var timeout = Debugger.IsAttached
5784
? Timeout.InfiniteTimeSpan // allow more flexible debugging expirience
58-
: timeoutMS <= 0 ? CoreTestConfiguration.DefaultTestTimeout : TimeSpan.FromMilliseconds(timeoutMS);
85+
: timeoutMS <= 0 ? XunitExtensionsConsts.DefaultTestTimeout : TimeSpan.FromMilliseconds(timeoutMS);
5986

6087

61-
var testLoggable = testClassInstance as LoggableTestClass;
88+
var testExceptionHandler = testClassInstance as ITestExceptionHandler;
6289

6390
decimal result;
6491
try
@@ -71,21 +98,21 @@ protected override async Task<decimal> InvokeTestMethodAsync(object testClassIns
7198
throw new TestTimeoutException((int)timeout.TotalMilliseconds);
7299
}
73100

74-
if (Aggregator.HasExceptions && testLoggable != null)
101+
if (Aggregator.HasExceptions && testExceptionHandler != null)
75102
{
76103
var exception = Aggregator.ToException();
77104

78105
if (exception is not SkipException)
79106
{
80-
testLoggable.OnException(exception);
107+
testExceptionHandler.HandleException(exception);
81108
}
82109
}
83110

84111
result = await baseTask;
85112
}
86113
catch (Exception exception)
87114
{
88-
testLoggable?.OnException(exception);
115+
testExceptionHandler?.HandleException(exception);
89116

90117
throw;
91118
}
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: 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 TimeoutEnforcingXunitTestMethodRunner : XunitTestMethodRunner
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
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
19+
{
20+
internal static class XunitConfiguration
21+
{
22+
public static TimeSpan DefaultTestTimeout { get; } = TimeSpan.FromMinutes(3);
23+
}
24+
}

tests/MongoDB.Bson.Tests/IO/BsonBinaryReaderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace MongoDB.Bson.Tests.IO
2828
{
2929
public class BsonBinaryReaderTests
3030
{
31-
[SkippableFact]
31+
[Fact]
3232
public void BsonBinaryReader_should_support_reading_more_than_2GB()
3333
{
3434
RequireEnvironment.Check().EnvironmentVariable("EXPLICIT");

tests/MongoDB.Bson.Tests/IO/BsonBinaryWriterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void BsonBinaryWriter_should_support_writing_multiple_documents(
5353
}
5454
}
5555

56-
[SkippableFact]
56+
[Fact]
5757
public void BsonBinaryWriter_should_support_writing_more_than_2GB()
5858
{
5959
RequireProcess.Check().Bits(64);
@@ -78,7 +78,7 @@ public void BsonBinaryWriter_should_support_writing_more_than_2GB()
7878
}
7979
}
8080

81-
[SkippableFact]
81+
[Fact]
8282
public void BackpatchSize_should_throw_when_size_is_larger_than_2GB()
8383
{
8484
RequireProcess.Check().Bits(64);

tests/MongoDB.Bson.Tests/IO/ByteBufferStreamTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void Position_set_should_throw_when_subject_is_disposed()
272272
action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("ByteBufferStream");
273273
}
274274

275-
[SkippableFact]
275+
[Fact]
276276
public void PrepareToWrite_should_throw_when_stream_would_exceed_2GB()
277277
{
278278
RequireProcess.Check().Bits(64);

tests/MongoDB.Bson.Tests/IO/JsonWriterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void TestDouble()
213213
}
214214
}
215215

216-
[SkippableFact]
216+
[Fact]
217217
public void TestDoubleRoundTripOn64BitProcess()
218218
{
219219
RequireProcess.Check().Bits(64);

tests/MongoDB.Bson.Tests/IO/MultiChunkBufferTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public void EnsureCapacity_should_throw_when_subject_is_read_only()
432432
action.ShouldThrow<InvalidOperationException>();
433433
}
434434

435-
[SkippableFact]
435+
[Fact]
436436
public void ExpandCapacity_should_throw_when_expanded_capacity_exceeds_2GB()
437437
{
438438
RequireProcess.Check().Bits(64);

tests/MongoDB.Bson.Tests/MongoDB.Bson.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
<PackageReference Include="Moq" Version="4.9.0" />
6565
<PackageReference Include="xunit" Version="2.4.2" />
6666
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
67-
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
6867
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" />
6968
</ItemGroup>
7069

0 commit comments

Comments
 (0)