Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
Koundinya Veluri committed Jul 27, 2021
commit a77ce962d2c4b29abcc30e0a4b8a3855d6b67b1e
45 changes: 45 additions & 0 deletions src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -949,6 +950,50 @@ void AppContextSetData(string name, object value)
}).Dispose();
}

[ConditionalFact(nameof(IsThreadingAndRemoteExecutorSupported))]
public static void CooperativeBlockingWithProcessingThreadsAndGoalThreadsAndAddWorkerRaceTest()
{
// Avoid contaminating the main process' environment
RemoteExecutor.Invoke(() =>
{
// The test is run affinitized to at most 2 processors for more frequent repros. The actual test process below
// will inherit the affinity.
Process testParentProcess = Process.GetCurrentProcess();
testParentProcess.ProcessorAffinity = (nint)testParentProcess.ProcessorAffinity & 0x3;

RemoteExecutor.Invoke(() =>
{
const uint TestDurationMs = 4000;

var done = new ManualResetEvent(false);
int startTimeMs = Environment.TickCount;
Action<object> completingTask = data => ((TaskCompletionSource<int>)data).SetResult(0);
Action repeatingTask = null;
repeatingTask = () =>
{
if ((uint)(Environment.TickCount - startTimeMs) >= TestDurationMs)
{
done.Set();
return;
}

Task.Run(repeatingTask);

var tcs = new TaskCompletionSource<int>();
Task.Factory.StartNew(completingTask, tcs);
tcs.Task.Wait();
};

for (int i = 0; i < Environment.ProcessorCount; ++i)
{
Task.Run(repeatingTask);
}

done.CheckedWait();
}).Dispose();
}).Dispose();
}

public static bool IsThreadingAndRemoteExecutorSupported =>
PlatformDetection.IsThreadingSupported && RemoteExecutor.IsSupported;
}
Expand Down