Skip to content

[Bug]: [After(TestSession)] hook incorrectly triggered on test timeout #4712

@epotter2297

Description

@epotter2297

Description

If a test times out, [After(TestSession)] hooks will fire additional times and run before dependent tests can execute

Expected Behavior

The Cleanup function should run exactly once after C

Actual Behavior

The Cleanup function runs once after B and a second time after C

Steps to Reproduce

public class Example
{
    [Test, Timeout(100)]
    public async Task A(CancellationToken token)
    {
        await Task.Delay(200, token);
        await Assert.That(true).IsEqualTo(true);
    }

    [Test]
    public async Task B()
    {
        await Task.Delay(300);
        await Assert.That(true).IsEqualTo(true);
    }

    [Test, DependsOn(nameof(B))]
    public async Task C()
    {
        await Assert.That(true).IsEqualTo(true);
    }
}

public static class ExampleHooks
{
    [After(TestSession)]
    public static async Task Cleanup()
    {
        await Assert.That(true).IsEqualTo(true);
    }
}

TUnit Version

1.13.11

.NET Version

.NET 10.0

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

This only seems to happen when the timeout occurs during the execution of the test method itself, and not if the test times out during the [Before] or [After] hooks

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions