Skip to content
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

[Bug] [Flaky test]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition #9277

Closed
jrdodds opened this issue Sep 26, 2023 · 1 comment · Fixed by #9215
Assignees
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. backlog bug triaged

Comments

@jrdodds
Copy link
Contributor

jrdodds commented Sep 26, 2023

Issue Description

The Microsoft.Build.UnitTests.BackEnd.BuildRequestEngine_Tests.TestBuildWithChildren unit test failed in a PR build with an the following assert:

Assert.Equal() Failure
Expected: Active
Actual: Idle

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

// Create the initial build request
string[] targets = new string[3] { "target1", "target2", "target3" };
BuildRequest request = CreateNewBuildRequest(1, targets);
// Kick it off
VerifyEngineStatus(BuildRequestEngineStatus.Uninitialized);
_engine.InitializeForBuild(new NodeLoggingContext(_host.LoggingService, 0, false));
_engine.SubmitBuildRequest(request);
Thread.Sleep(250);
VerifyEngineStatus(BuildRequestEngineStatus.Active);

The code assumes that after the Thread.Sleep(250) at line 407, the engine status will be Active. Instead, the engine status may be Idle. There is a second instance of calling Thread.Sleep() and VerifyEngineStatus() 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

@jrdodds jrdodds added bug needs-triage Have yet to determine what bucket this goes in. labels Sep 26, 2023
@JaynieBai
Copy link
Member

JaynieBai commented Sep 28, 2023

Related with #9100 and fixing with PR #9215

@jrdodds jrdodds changed the title [Bug]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition [Bug], [Flaky test]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition Oct 2, 2023
@jrdodds jrdodds changed the title [Bug], [Flaky test]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition [Bug] [Flaky test] TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition Oct 2, 2023
@jrdodds jrdodds changed the title [Bug] [Flaky test] TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition [Bug] [Flaky test]: TestBuildWithChildren unit test is unreliable and may fail on an apparent race condition Oct 2, 2023
@AR-May AR-May added Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. backlog and removed needs-triage Have yet to determine what bucket this goes in. labels Oct 3, 2023
@GangWang01 GangWang01 self-assigned this Oct 8, 2023
@GangWang01 GangWang01 linked a pull request Oct 11, 2023 that will close this issue
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Our Own Build Problems affecting the build or build infrastructure of the MSBuild repo itself. backlog bug triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants