-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18975d0
commit 37886d5
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using NUnit.Framework; | ||
using Octopus.Tentacle.Tests.Integration.Support.TestAttributes; | ||
|
||
[assembly: Parallelizable(ParallelScope.All)] | ||
[assembly: Parallelizable(ParallelScope.All)] | ||
[assembly: CustomLevelOfParallelism] |
18 changes: 18 additions & 0 deletions
18
source/Octopus.Tentacle.Tests.Integration/Support/HowManyParallelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Octopus.Tentacle.Tests.Integration.Support.TestAttributes; | ||
|
||
namespace Octopus.Tentacle.Tests.Integration.Support | ||
{ | ||
public class HowManyParallelTests : IntegrationTest | ||
{ | ||
[Test] | ||
public void HowManyTestsAreRunningInParallel() | ||
{ | ||
// Only exists to make it easy to find out how many tests are running in parallel. | ||
Logger.Information("The number of parallel tests are: {LevelOfParallelism} on a machine with {NumberOfCpuCores} cpu cores.", | ||
CustomLevelOfParallelismAttribute.LevelOfParallelism(), | ||
Environment.ProcessorCount); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...us.Tentacle.Tests.Integration/Support/TestAttributes/CustomLevelOfParallelismAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Api; | ||
using Octopus.Tentacle.Util; | ||
|
||
namespace Octopus.Tentacle.Tests.Integration.Support.TestAttributes | ||
{ | ||
/// <summary> | ||
/// Halibut tests take time but don't use lots of CPU. | ||
/// | ||
/// For local development by default increase the level of parallelism to 2x the number of Cores. | ||
/// | ||
/// This can be overriden with the environment variable "CustomLevelOfParallelism" e.g. | ||
/// CustomLevelOfParallelism=256 | ||
/// | ||
/// When run in the build the default level is always used. | ||
/// </summary> | ||
[AttributeUsage( AttributeTargets.Assembly, AllowMultiple=false, Inherited=false )] | ||
public class CustomLevelOfParallelismAttribute : PropertyAttribute | ||
{ | ||
public CustomLevelOfParallelismAttribute() : base(LevelOfParallelismAttributePropertyName(), LevelOfParallelism()) | ||
{ | ||
} | ||
|
||
public static int LevelOfParallelism() | ||
{ | ||
if (TeamCityDetection.IsRunningInTeamCity()) | ||
{ | ||
return LevelOfParallelismFromEnvVar() ?? NUnitTestAssemblyRunner.DefaultLevelOfParallelism * 2; | ||
} | ||
|
||
return LevelOfParallelismFromEnvVar() ?? NUnitTestAssemblyRunner.DefaultLevelOfParallelism * 2; | ||
} | ||
|
||
static int? LevelOfParallelismFromEnvVar() | ||
{ | ||
var nunitLevelOfParallelismSetting = Environment.GetEnvironmentVariable("CustomLevelOfParallelism"); | ||
if (!string.IsNullOrEmpty(nunitLevelOfParallelismSetting)) | ||
{ | ||
if (int.TryParse(nunitLevelOfParallelismSetting, out var level)) | ||
{ | ||
return level; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
static string LevelOfParallelismAttributePropertyName() | ||
{ | ||
string propertyName = typeof(LevelOfParallelismAttribute).Name; | ||
if ( propertyName.EndsWith( "Attribute" ) ) | ||
propertyName = propertyName.Substring( 0, propertyName.Length - 9 ); | ||
return propertyName; | ||
} | ||
} | ||
} |