-
-
Notifications
You must be signed in to change notification settings - Fork 978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flaky tests because of AssertAllocations with InProcessEmitToolchain on Windows #1925
Comments
For these particular tests, and in case of For example, this repro, which doesn't involve BDN at all, will always have some test failures, and only for the total bytes count. The number of failures is reduced if you set the processor count to 1, but even then they still happen. using System;
using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;
namespace TestProject1
{
public static class Engine {
public static int ParallelTestCount = 0;
[MethodImpl(MethodImplOptions.NoInlining)]
public static ValueTuple<int> ReturnsValueType() => new ValueTuple<int>(0);
public static void Run(int dummy)
{
int parallelTests = Interlocked.Increment(ref Engine.ParallelTestCount);
GC.Collect();
long bytesForThread = GC.GetAllocatedBytesForCurrentThread();
long bytesTotal = GC.GetTotalAllocatedBytes();
_ = dummy;
try
{
_ = ReturnsValueType();
GC.Collect();
bytesForThread = GC.GetAllocatedBytesForCurrentThread() - bytesForThread;
bytesTotal = GC.GetTotalAllocatedBytes() - bytesTotal;
Assert.Equal(1, parallelTests);
Assert.Equal(0, bytesForThread);
Assert.Equal(0, bytesTotal);
}
finally
{
Interlocked.Decrement(ref Engine.ParallelTestCount);
}
}
}
public class UnitTest1
{
private class MyData1 : TheoryData<int> { public MyData1() { for (int i = 0; i < 100; i++) Add(i); } }
[Theory] [ClassData(typeof(MyData1))] public void Test1(int dummy) { Engine.Run(dummy); }
private class MyData2 : TheoryData<int> { public MyData2() { for (int i = 0; i < 100; i++) Add(i); } }
[Theory] [ClassData(typeof(MyData2))] public void Test2(int dummy) { Engine.Run(dummy); }
private class MyData3 : TheoryData<int> { public MyData3() { for (int i = 0; i < 100; i++) Add(i); } }
[Theory] [ClassData(typeof(MyData3))] public void Test3(int dummy) { Engine.Run(dummy); }
}
} |
Addendum:
Yeah, that would render the tests meaningless, since the InProcessEmitToolChain starts a thread... (slightly embarrassed) Still, the point remains, you have no control what the testhost/testrunner does. Even using vstest with |
We have disabled the xUnit parallelization for these tests:
So in theory given benchmark should be the only running thread except of Tiered JIT and GC threads.
Perhaps we should exclude these tests for Windows?
|
Yes, I know, I did that too. I also included an assertion for that (because I'm paranoid). And I disabled the long-running test watchdog, since it has its own thread. Then there is a message sink thread that uses Sockets, and some other threads I couldn't make out the purpose of during a quick look with the Debugger - in short, a lot is going on in the background, even if the tests itself are not running parallel. Why that seems to be a problem only on Windows I have no idea. I guess the only way to un-flaky them is running the InProcessEmitToolchain tests out-of-process...
Or that. 😀 |
…s toolchain as it's flaky, contributes to #1925
MemoryDiagnoserTests.AssertAllocations
frequently fails GitHub/Windows builds. Test examples:EngineShouldNotIntroduceBoxing
,AwaitingTasksShouldNotInterfereAllocationResults
.Some recently failed builds:
https://github.com/dotnet/BenchmarkDotNet/runs/5218066245
https://github.com/dotnet/BenchmarkDotNet/runs/5108471012
The text was updated successfully, but these errors were encountered: