Skip to content

Commit dfaceae

Browse files
Copilotthomhurst
andcommitted
Fix TimeoutAttribute not being applied to non-test hooks
The TimeoutAttribute on [Before(Assembly)], [Before(Class)], [Before(TestSession)], and [Before(TestDiscovery)] hooks was being ignored because ProcessHookRegistrationAsync was not being called for these hooks. This commit: - Adds async versions of hook delegate creation methods that call ProcessHookRegistrationAsync - Updates InitializeAsync to await the async hook building methods - Converts CollectBeforeAssemblyHooksAsync, CollectAfterAssemblyHooksAsync, CollectBeforeClassHooksAsync, and CollectAfterClassHooksAsync to properly process hook registration events - Adds HookTimeoutTests to verify the fix works for class and assembly hooks Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
1 parent 98eab14 commit dfaceae

File tree

3 files changed

+342
-134
lines changed

3 files changed

+342
-134
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Shouldly;
2+
using TUnit.Engine.Tests.Enums;
3+
4+
namespace TUnit.Engine.Tests;
5+
6+
public class HookTimeoutTests(TestMode testMode) : InvokableTestBase(testMode)
7+
{
8+
public async Task ClassHook_WithTimeout_ShouldFail()
9+
{
10+
await RunTestsWithFilter(
11+
"/*/*/ClassHookTimeoutTests/*",
12+
[
13+
result => result.ResultSummary.Outcome.ShouldBe("Failed"),
14+
result => result.ResultSummary.Counters.Total.ShouldBe(1),
15+
result => result.ResultSummary.Counters.Passed.ShouldBe(0),
16+
result => result.ResultSummary.Counters.Failed.ShouldBe(1),
17+
]);
18+
}
19+
20+
public async Task AssemblyHook_WithTimeout_ShouldPass()
21+
{
22+
await RunTestsWithFilter(
23+
"/*/*/AssemblyHookTimeoutPassTests/*",
24+
[
25+
result => result.ResultSummary.Outcome.ShouldBe("Completed"),
26+
result => result.ResultSummary.Counters.Total.ShouldBe(1),
27+
result => result.ResultSummary.Counters.Passed.ShouldBe(1),
28+
result => result.ResultSummary.Counters.Failed.ShouldBe(0),
29+
]);
30+
}
31+
}

0 commit comments

Comments
 (0)