-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathTestAssemblySettingsProvider.cs
More file actions
57 lines (46 loc) · 2.16 KB
/
TestAssemblySettingsProvider.cs
File metadata and controls
57 lines (46 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Security;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
internal sealed class TestAssemblySettingsProvider : MarshalByRefObject
{
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete]
#endif
public override object InitializeLifetimeService() => null!;
[SuppressMessage(
"Performance",
"CA1822:Mark members as static",
Justification = "Intentionally not static. We call it from a different AppDomain")]
internal TestAssemblySettings GetSettings(string source)
{
var testAssemblySettings = new TestAssemblySettings();
// Load the source.
Assembly testAssembly = PlatformServiceProvider.Instance.FileOperations.LoadAssembly(source);
IReflectionOperations reflectionOperations = PlatformServiceProvider.Instance.ReflectionOperations;
ParallelizeAttribute? parallelizeAttribute = reflectionOperations.GetCustomAttributes(testAssembly, typeof(ParallelizeAttribute))
.OfType<ParallelizeAttribute>()
.FirstOrDefault();
if (parallelizeAttribute != null)
{
testAssemblySettings.Workers = parallelizeAttribute.Workers;
testAssemblySettings.Scope = parallelizeAttribute.Scope;
if (testAssemblySettings.Workers == 0)
{
testAssemblySettings.Workers = Environment.ProcessorCount;
}
}
testAssemblySettings.CanParallelizeAssembly = reflectionOperations.GetCustomAttributes(testAssembly, typeof(DoNotParallelizeAttribute)).Length == 0;
return testAssemblySettings;
}
}