Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion tests/TUnit.Engine.Tests/InvokableTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ private async Task RunWithAot(string filter, List<Action<TestRun>> assertions,
"--report-trx", "--report-trx-filename", trxFilename,
"--diagnostic-verbosity", "Debug",
"--diagnostic", "--diagnostic-file-prefix", $"log_{GetType().Name}_AOT_",
"--timeout", "5m",
// A whole-session budget, not a hang detector. The [EngineTest=Pass] run takes
// 3.5-5 minutes on Windows CI, so a 5m budget cancelled healthy runs mid-way
// through the sequential global [NotInParallel] tail.
"--timeout", "10m",
..runOptions.AdditionalArguments
]
)
Expand Down
20 changes: 20 additions & 0 deletions tests/TUnit.TestProject/Bugs/6885/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class DedicatedThreadExecutorCleanUpOrderTests

private static async Task AssertNoOverlapAsync()
{
SlowCleanUpExecutor.MarkTestBodyRunning();

var cleanUpRunningAtStart = SlowCleanUpExecutor.CleanUpRunning;

// Longer than CleanUp(), so a previous test's late CleanUp() would reset the state mid-test.
Expand All @@ -40,22 +42,40 @@ private static async Task AssertNoOverlapAsync()
/// <summary>
/// Sets global state in Initialize() and resets it in a slow CleanUp().
/// </summary>
/// <remarks>
/// The executor also runs every Before/After(Test) hook, including the project's many global
/// [BeforeEvery]/[AfterEvery] hooks, each on its own dedicated thread. Only the test body's
/// CleanUp() is slow: sleeping after every hook made each of these [NotInParallel] tests take
/// about 16 seconds, which pushed the [EngineTest=Pass] run past its time budget.
/// </remarks>
public sealed class SlowCleanUpExecutor : DedicatedThreadExecutor
{
private static volatile bool s_cleanUpRunning;
private static volatile string s_state = "reset";

// The test body runs on the executor's dedicated thread (its continuations are pumped there),
// so a thread-static flag tells CleanUp() whether this thread ran a test body or a hook.
[ThreadStatic]
private static bool t_ranTestBody;

public static bool CleanUpRunning => s_cleanUpRunning;

public static string State => s_state;

public static void MarkTestBodyRunning() => t_ranTestBody = true;

protected override void Initialize()
{
s_state = "configured";
}

protected override void CleanUp()
{
if (!t_ranTestBody)
{
return;
Comment thread
thomhurst marked this conversation as resolved.
}

s_cleanUpRunning = true;
Thread.Sleep(300);
s_state = "reset";
Expand Down
Loading