-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6253 from smoogipoo/fix-flaky-tests
Fix flaky test attribute not working
- Loading branch information
Showing
8 changed files
with
119 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace osu.Framework.Tests | ||
|
@@ -18,7 +17,7 @@ public FlakyTestAttribute() | |
} | ||
|
||
public FlakyTestAttribute(int tryCount) | ||
: base(Environment.GetEnvironmentVariable("OSU_TESTS_FAIL_FLAKY") == "1" ? 1 : tryCount) | ||
: base(FrameworkEnvironment.FailFlakyTests ? 1 : tryCount) | ||
{ | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
using osu.Framework.Testing; | ||
|
||
namespace osu.Framework.Tests.Visual.Testing | ||
{ | ||
[HeadlessTest] | ||
public partial class TestSceneTestRetry : FrameworkTestScene | ||
{ | ||
private int runCount; | ||
private string? currentTest; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetup() | ||
{ | ||
if (FrameworkEnvironment.FailFlakyTests) | ||
Assert.Ignore("Can't run while failing flaky tests."); | ||
} | ||
|
||
[SetUp] | ||
public void Setup() => Schedule(() => | ||
{ | ||
if (currentTest == TestExecutionContext.CurrentContext.CurrentTest.Name) | ||
return; | ||
|
||
runCount = 0; | ||
currentTest = TestExecutionContext.CurrentContext.CurrentTest.Name; | ||
}); | ||
|
||
[Test] | ||
[FlakyTest(10)] | ||
public void FlakyTestWithAssert() | ||
{ | ||
AddStep("increment", () => runCount++); | ||
AddAssert("assert if not ran 5 times", () => runCount, () => Is.EqualTo(5)); | ||
} | ||
|
||
[Test] | ||
[FlakyTest(3)] | ||
public void FlakyTestWithUntilStep() | ||
{ | ||
AddStep("increment", () => runCount++); | ||
AddUntilStep("assert if not ran 2 times", () => runCount, () => Is.EqualTo(2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters