Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fd08a1e

Browse files
committed
Merge pull request #2814 from stephentoub/task_tests_time
Reduce running time of Tasks tests
2 parents affc049 + c755267 commit fd08a1e

File tree

6 files changed

+14
-16
lines changed

6 files changed

+14
-16
lines changed

src/System.Threading.Tasks/tests/CESchedulerPairTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void TestCreationOptions(String ctorType)
101101
ConcurrentExclusiveSchedulerPair schedPair = null;
102102
//Need to define the default values since these values are passed to the verification methods
103103
TaskScheduler scheduler = TaskScheduler.Default;
104-
int maxConcurrentLevel = 4;
104+
int maxConcurrentLevel = Environment.ProcessorCount;
105105

106106
//Based on input args, use one of the ctor overloads
107107
switch (ctorType.ToLower())
@@ -283,7 +283,7 @@ public static void TestLowerConcurrencyLevel()
283283
blockMainThreadEvent.WaitOne(); // wait for the blockedTask to start execution
284284

285285
//Now add more reader tasks
286-
int maxConcurrentTasks = 8;
286+
int maxConcurrentTasks = Environment.ProcessorCount;
287287
List<Task> taskList = new List<Task>();
288288
for (int i = 0; i < maxConcurrentTasks; i++)
289289
taskList.Add(readers.StartNew(() => { })); //schedule some dummy reader tasks
@@ -339,7 +339,7 @@ public static void TestConcurrentBlockage(bool useReader)
339339
public static void TestIntegration(String apiType, bool useReader)
340340
{
341341
Debug.WriteLine(string.Format(" Running apiType:{0} useReader:{1}", apiType, useReader));
342-
int taskCount = 8; //To get varying number of tasks as a function of cores
342+
int taskCount = Environment.ProcessorCount; //To get varying number of tasks as a function of cores
343343
ConcurrentExclusiveSchedulerPair schedPair = new ConcurrentExclusiveSchedulerPair();
344344
CountdownEvent cde = new CountdownEvent(taskCount); //Used to track how many tasks were executed
345345
Action work = () => { cde.Signal(); }; //Work done by all APIs
@@ -396,7 +396,7 @@ public static void TestCompletionTask()
396396

397397
// Can create a bunch of schedulers, do work on them all, complete them all, and they all complete
398398
{
399-
var cesps = new ConcurrentExclusiveSchedulerPair[1000];
399+
var cesps = new ConcurrentExclusiveSchedulerPair[100];
400400
for (int i = 0; i < cesps.Length; i++)
401401
{
402402
cesps[i] = new ConcurrentExclusiveSchedulerPair();
@@ -504,7 +504,7 @@ public static void TestSchedulerNesting()
504504
[InlineData(false)]
505505
public static void TestConcurrentExclusiveChain(bool syncContinuations)
506506
{
507-
var scheduler = new TrackingTaskScheduler(8);
507+
var scheduler = new TrackingTaskScheduler(Environment.ProcessorCount);
508508
var cesp = new ConcurrentExclusiveSchedulerPair(scheduler);
509509

510510
// continuations

src/System.Threading.Tasks/tests/MethodCoverage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void TaskWait_MaxInt32()
2727
[OuterLoop]
2828
public static void TaskContinuation()
2929
{
30-
int taskCount = 4;
30+
int taskCount = Environment.ProcessorCount;
3131
int maxDOP = Int32.MaxValue;
3232
int maxNumberExecutionsPerTask = 1;
3333
int data = 0;

src/System.Threading.Tasks/tests/Task/TaskRtTests_Core.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,9 +1130,7 @@ private static int NestedLevels(Exception e)
11301130
[Fact]
11311131
public static void RunTaskWaitAnyTests()
11321132
{
1133-
//int numCores = Environment.ProcessorCount;]
1134-
// We are just selecting a number since Environment exists in a .dll that is not part of the contracts.
1135-
int numCores = 4;
1133+
int numCores = Environment.ProcessorCount;
11361134

11371135
// Basic tests w/ <64 tasks
11381136
CoreWaitAnyTest(0, new bool[] { }, -1);
@@ -1591,10 +1589,7 @@ public static void RunLongRunningTaskTests()
15911589
// This is computed such that this number of long-running tasks will result in a back-up
15921590
// without some assistance from TaskScheduler.RunBlocking() or TaskCreationOptions.LongRunning.
15931591

1594-
// We are selecting some number because Environment exists in a .dll that is not
1595-
// part of the contracts we are testing.
1596-
//int ntasks = Environment.ProcessorCount * 2;
1597-
int ntasks = 8;
1592+
int ntasks = Environment.ProcessorCount * 2;
15981593

15991594
Task[] tasks = new Task[ntasks];
16001595
ManualResetEvent mre = new ManualResetEvent(false); // could just use a bool?

src/System.Threading.Tasks/tests/Task/TaskRunSyncTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ public static void TaskRunSyncTest2()
434434
test.RealRun();
435435
}
436436
[Fact]
437+
[OuterLoop]
437438
public static void TaskRunSyncTest3()
438439
{
439440
TestParameters_RunSync parameters = new TestParameters_RunSync(PreTaskStatus.Completed, PostRunSyncAction.Wait, WorkloadType.CreateChildTask, TaskCreationOptions.None, TaskSchedulerType.CustomWithInlineExecution);

src/System.Threading.Tasks/tests/Task/TaskWaitAllAnyTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ public static void TaskWaitAllAny30()
809809
}
810810

811811
[Fact]
812+
[OuterLoop]
812813
public static void TaskWaitAllAny31()
813814
{
814815
TaskInfo node1 = new TaskInfo(WorkloadType.Medium);
@@ -904,6 +905,7 @@ public static void TaskWaitAllAny33()
904905
}
905906

906907
[Fact]
908+
[OuterLoop]
907909
public static void TaskWaitAllAny34()
908910
{
909911
TaskInfo node1 = new TaskInfo(WorkloadType.Medium);
@@ -940,6 +942,7 @@ public static void TaskWaitAllAny36()
940942
}
941943

942944
[Fact]
945+
[OuterLoop]
943946
public static void TaskWaitAllAny37()
944947
{
945948
TaskInfo node1 = new TaskInfo(WorkloadType.VeryHeavy);
@@ -1027,6 +1030,7 @@ public static void TaskWaitAllAny44()
10271030
}
10281031

10291032
[Fact]
1033+
[OuterLoop]
10301034
public static void TaskWaitAllAny45()
10311035
{
10321036
TaskInfo node1 = new TaskInfo(WorkloadType.Medium);

src/System.Threading.Tasks/tests/TaskScheduler/TaskSchedulerTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public static void RunBlockedInjectionTest()
3636

3737
// Create many tasks blocked on the MRE.
3838

39-
// WE are specifying a fixed number rather than using environment.processorcount because it uses a .dll that is not
40-
// in the contracts.
41-
int processorCount = 8;
39+
int processorCount = Environment.ProcessorCount;
4240
Task[] tasks = new Task[processorCount];
4341
for (int i = 0; i < tasks.Length; i++)
4442
{

0 commit comments

Comments
 (0)