Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: TimeoutAttribute on [Before(Assembly)] hook is ignored - default 5 minute timeout always used #4114

Copy link
Copy link

Description

@bergmania
Issue body actions

Description

The [Timeout] attribute placed on a [Before(Assembly)] hook method is not being applied. The hook always uses the default 5-minute timeout (300,000ms) defined in HookMethod.cs, regardless of the timeout value specified in the attribute.

Expected Behavior

The hook should use the 15-minute timeout specified in the [Timeout(900_000)] attribute.

Actual Behavior

The hook fails with:

TUnit.Engine.Exceptions.TestFailedException: BeforeAssemblyException: BeforeAssembly hook failed:
Hook 'IntegrationTestsBase.SetUp()' exceeded timeout of 300000ms

The timeout is always 300,000ms (5 minutes) - the default value from HookMethod.Timeout.

Steps to Reproduce

  1. Create a test class with a [Before(Assembly)] hook that takes longer than 5 minutes on slow CI/CD environments
  2. Add [Timeout(900_000)] attribute to increase timeout to 15 minutes
  3. Run the tests
public abstract class IntegrationTestsBase                                                                                                                                     
{                                                                                                                                                                              
    [Timeout(900_000)] // 15 minutes - THIS IS IGNORED                                                                                                                         
    [Before(Assembly)]                                                                                                                                                         
    public static async Task SetUp(CancellationToken cancellationToken)                                                                                                        
    {                                                                                                                                                                          
        // Long-running setup (starting containers, etc.)                                                                                                                      
        await Task.Delay(TimeSpan.FromMinutes(6), cancellationToken);                                                                                                          
    }                                                                                                                                                                          
}                                                                                                                                                                              

TUnit Version

1.5.80

.NET Version

.NET 10.0

Operating System

Linux

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

TUnit.Engine.Exceptions.TestFailedException: BeforeAssemblyException: BeforeAssembly hook failed: Hook 'AspireIntegrationTestsBase.SetUp(cancellationToken)' exceeded timeout of 300000ms
  --->  System.TimeoutException: Hook 'AspireIntegrationTestsBase.SetUp(cancellationToken)' exceeded timeout of 300000ms
    at TUnit.Engine.Helpers.HookTimeoutHelper.<>c__DisplayClass0_0`1.<<CreateTimeoutHookAction>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
    at TUnit.Engine.Services.HookCollectionService.<>c__DisplayClass56_0.<<CreateAssemblyHookDelegate>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    at TUnit.Engine.Services.HookExecutor.ExecuteBeforeAssemblyHooksAsync(Assembly assembly, CancellationToken cancellationToken)

Additional Context

Analysis

Looking at the TUnit source code:

  1. HookMethod.cs defines: public TimeSpan? Timeout { get; internal set; } = TimeSpan.FromMinutes(5);
  2. TimeoutAttribute implements IHookRegisteredEventReceiver with OnHookRegistered that should set context.Timeout
  3. EventReceiverOrchestrator.InvokeHookRegistrationEventReceiversAsync should call OnHookRegistered and then set hookMethod.Timeout = hookContext.Timeout

It appears that either:

  • InvokeHookRegistrationEventReceiversAsync is not being called for assembly hooks, OR
  • The TimeoutAttribute is not being discovered via reflection on the MethodMetadata

Workarounds Attempted

  • [assembly: Timeout(900_000)] - did not work for hooks
  • Custom IHookExecutor - timeout is applied before executor is called

IDE-Specific Issue?

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

Metadata

Metadata

Labels

bugSomething isn't workingSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.