Skip to content

Commit 44ef5df

Browse files
committed
CSHARP-3807: XUnit custom timeouts infrastructure
1 parent 547570b commit 44ef5df

File tree

79 files changed

+1413
-83
lines changed

Some content is hidden

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

79 files changed

+1413
-83
lines changed

build.cake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ Task("Test")
155155

156156
var testResultsFile = outputDirectory.Combine("test-results").Combine($"TEST-{target.ToLowerInvariant()}-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.xml");
157157
// Evergreen CI server requires JUnit output format to display test results
158-
var logger = $"junit;LogFilePath={testResultsFile};FailureBodyFormat=Verbose";
158+
var junitLogger = $"junit;LogFilePath={testResultsFile};FailureBodyFormat=Verbose";
159+
var consoleLogger = "console;verbosity=detailed";
160+
159161
var settings = new DotNetCoreTestSettings
160162
{
161163
NoBuild = true,
162164
NoRestore = true,
163165
Configuration = configuration,
164-
Logger = logger,
166+
Loggers = new string[] { consoleLogger, junitLogger },
165167
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64")
166168
};
167169
switch (target.ToLowerInvariant()) // target can be not only moniker related

evergreen/evergreen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ stepback: true
1313
command_type: system
1414

1515
# Protect ourself against rogue test case, or curl gone wild, that runs forever
16-
# 12 minutes is the longest we'll ever run
17-
exec_timeout_secs: 1800
16+
# 45 minutes: 20 minutes is a normal test run + up to 10 minutes for test setup + 15 minutes for longer macOS tests
17+
exec_timeout_secs: 2700
1818

1919
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
2020
timeout:

tests/AtlasConnectivity.Tests/ConnectivityTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@
1717
using FluentAssertions;
1818
using MongoDB.Bson;
1919
using MongoDB.Driver;
20+
using MongoDB.Driver.Core.TestHelpers.Logging;
2021
using MongoDB.Driver.TestHelpers;
2122
using Xunit;
23+
using Xunit.Abstractions;
2224

2325
namespace AtlasConnectivity.Tests
2426
{
25-
public class ConnectivityTests
27+
public class ConnectivityTests : LoggableTestClass
2628
{
29+
// public constructors
30+
public ConnectivityTests(ITestOutputHelper testOutputHelper)
31+
: base(testOutputHelper)
32+
{
33+
}
34+
35+
// public methods
2736
[Theory]
2837
[InlineData("ATLAS_FREE")]
2938
[InlineData("ATLAS_FREE_SRV")]
@@ -62,7 +71,7 @@ private DisposableMongoClient CreateDisposableClient(string connectionString)
6271
{
6372
var clientSettings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
6473
var client = new MongoClient(clientSettings);
65-
return new DisposableMongoClient(client);
74+
return new DisposableMongoClient(client, CreateLogger<DisposableMongoClient>());
6675
}
6776
}
6877
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"longRunningTestSeconds": 1800,
2+
"longRunningTestSeconds": 10,
33
"parallelizeAssembly": false,
44
"parallelizeTestCollections": false
55
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PackageReference Include="FluentAssertions" Version="4.12.0" />
3838
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" />
3939
<PackageReference Include="xunit" Version="2.4.0" />
40-
<PackageReference Include="Xunit.SkippableFact" Version="1.3.6" />
40+
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
4141
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" />
4242
</ItemGroup>
4343

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"longRunningTestSeconds": 1800,
2+
"longRunningTestSeconds": 10,
33
"parallelizeAssembly": false,
44
"parallelizeTestCollections": false
55
}

tests/MongoDB.Driver.Core.TestHelpers/CoreTestConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public static class CoreTestConfiguration
5151
private static Lazy<string> __storageEngine = new Lazy<string>(GetStorageEngine, isThreadSafe: true);
5252
private static TraceSource __traceSource;
5353

54+
public static TimeSpan DefaultTestTimeout { get; } = TimeSpan.FromMinutes(3);
55+
5456
// static properties
5557
public static ICluster Cluster
5658
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright 2021-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+
namespace MongoDB.Driver.Core.TestHelpers.Logging
17+
{
18+
public interface ILogger
19+
{
20+
public void Log(LogLevel logLevel, string decoration, string format, params object[] arguments);
21+
}
22+
23+
public interface ILogger<TCategory> : ILogger
24+
{
25+
}
26+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Copyright 2021-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+
namespace MongoDB.Driver.Core.TestHelpers.Logging
17+
{
18+
public static class ILoggerExtensions
19+
{
20+
public static ILogger<T> Decorate<T>(this ILogger<T> logger, string decoration) =>
21+
logger != null ? new LoggerDecorator<T>(logger, decoration) : null;
22+
23+
public static void Error(this ILogger logger, string format, params object[] arguments) =>
24+
logger?.Log(LogLevel.Error, null, format, arguments);
25+
26+
public static void Error<T>(this ILogger<T> logger, string message, params object[] arguments) =>
27+
logger?.Log(LogLevel.Error, null, message, arguments);
28+
29+
public static void Warning(this ILogger logger, string format, params object[] arguments) =>
30+
logger?.Log(LogLevel.Warning, null, format, arguments);
31+
32+
public static void Warning<T>(this ILogger<T> logger, string message, params object[] arguments) =>
33+
logger?.Log(LogLevel.Warning, null, message, arguments);
34+
35+
public static void Info(this ILogger logger, string format, params object[] arguments) =>
36+
logger?.Log(LogLevel.Information, null, format, arguments);
37+
38+
public static void Info<T>(this ILogger<T> logger, string message, params object[] arguments) =>
39+
logger?.Log(LogLevel.Information, null, message, arguments);
40+
41+
public static void Debug(this ILogger logger, string format, params object[] arguments) =>
42+
logger?.Log(LogLevel.Debug, null, format, arguments);
43+
44+
public static void Debug<T>(this ILogger<T> logger, string message, params object[] arguments) =>
45+
logger?.Log(LogLevel.Debug, null, message, arguments);
46+
47+
public static void Trace(this ILogger logger, string format, params object[] arguments) =>
48+
logger?.Log(LogLevel.Trace, null, format, arguments);
49+
50+
public static void Trace<T>(this ILogger<T> logger, string format, params object[] arguments) =>
51+
logger?.Log(LogLevel.Trace, null, format, arguments);
52+
}
53+
54+
internal static class ILoggerFactoryExtensions
55+
{
56+
public static ILogger<TCategory> CreateLogger<TCategory>(this ILoggerFactory loggerFactory, string decoration) =>
57+
loggerFactory?.CreateLogger<TCategory>().Decorate(decoration);
58+
}
59+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright 2021-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+
namespace MongoDB.Driver.Core.TestHelpers.Logging
17+
{
18+
public interface ILoggerFactory
19+
{
20+
public ILogger<TCategory> CreateLogger<TCategory>();
21+
}
22+
}

0 commit comments

Comments
 (0)