[Bug] [Flaky test]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition #9277
Labels
Area: Our Own Build
Problems affecting the build or build infrastructure of the MSBuild repo itself.
backlog
bug
triaged
Issue Description
The
Microsoft.Build.UnitTests.BackEnd.BuildRequestEngine_Tests.TestBuildWithChildren
unit test failed in a PR build with an the following assert:The location of the error is src\Build.UnitTests\BackEnd\BuildRequestEngine_Tests.cs:line 408
A subsequent build, different only by a change to a comment, succeeded.
Steps to Reproduce
Run the set of unit tests.
It appears to be a threading race condition and the test doesn't always break.
Expected Behavior
The unit test should be reliable and test what it is intended to test.
Actual Behavior
The unit test may fail while creating the conditions for the test.
Analysis
msbuild/src/Build.UnitTests/BackEnd/BuildRequestEngine_Tests.cs
Lines 399 to 409 in 0bc6323
The code assumes that after the
Thread.Sleep(250)
at line 407, the engine status will beActive
. Instead, the engine status may beIdle
. There is a second instance of callingThread.Sleep()
andVerifyEngineStatus()
later in the test method.Sleeping for an arbitrary time and then assuming a certain state is inherently risky. Can this test be implemented without using
Thread.Sleep()
?Versions & Configurations
MSBuild version 17.9.0-dev-23476-01+abb507c0a for .NET
17.9.0.47601
The text was updated successfully, but these errors were encountered: