Skip to content

Commit 70c2edb

Browse files
Copilotthomhurstclaude[bot]claude
authored
+semver:minor - Add timeout functionality for hooks with 5-minute default timeout (#2891)
* Initial plan * Implement hook timeout functionality with 5-minute default timeout Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com> * Update public API snapshots to approve hook timeout changes Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com> * Implement proper hook timeout functionality with event receiver pattern - Fix TimeoutAttribute.OnHookRegistered to actually set timeout on context - Extend HookRegisteredContext to support both static and instance hook methods - Update hook method classes to use settable timeout property instead of direct attribute access - Add hook registration event receiver infrastructure to EventReceiverOrchestrator - Modify HookCollectionService to trigger hook registration events during delegate creation - Reorder service initialization to inject EventReceiverOrchestrator into HookCollectionService This implementation follows the established event receiver pattern used for tests, ensuring that TimeoutAttribute and other hook attributes can modify hook properties during registration rather than relying on direct attribute access. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Refactor hook methods to share unified HookMethod base class - Created abstract HookMethod base record with all shared properties - StaticHookMethod and InstanceHookMethod now inherit from HookMethod - Simplified HookRegisteredContext to work with single HookMethod type - Reduced EventReceiverOrchestrator hook processing from 15 lines to 3 - Simplified HookCollectionService hook registration logic - Hook event receivers now only need to handle HookMethod instead of both types Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com> * Fix hook timeout implementation for PR #2891 - Fixed InstanceHookMethod to use InitClassType property instead of trying to override ClassType with init accessor - Updated source generators to generate InitClassType instead of ClassType for InstanceHookMethod - Fixed async/await issues in HookCollectionService by restructuring methods to avoid async lambdas - Added proper DynamicallyAccessedMembers annotations for trimming compatibility - Fixed EventReceiverOrchestrator to use HookMethod property from HookRegisteredContext * fix: Update InstanceHookMethod property from ClassType to InitClassType in test files * fix: Add HookRegisteredContext and update Timeout handling in hook methods --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com>
1 parent b323b58 commit 70c2edb

20 files changed

+498
-219
lines changed

TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
3535
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)].Add(
3636
new InstanceHookMethod
3737
{
38-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
38+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
3939
MethodInfo = new global::TUnit.Core.MethodMetadata
4040
{
4141
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
@@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
7777
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)].Add(
7878
new InstanceHookMethod
7979
{
80-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
80+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
8181
MethodInfo = new global::TUnit.Core.MethodMetadata
8282
{
8383
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
@@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
119119
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)].Add(
120120
new InstanceHookMethod
121121
{
122-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
122+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
123123
MethodInfo = new global::TUnit.Core.MethodMetadata
124124
{
125125
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
@@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
161161
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
162162
new InstanceHookMethod
163163
{
164-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
164+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
165165
MethodInfo = new global::TUnit.Core.MethodMetadata
166166
{
167167
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
@@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
202202
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
203203
new InstanceHookMethod
204204
{
205-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
205+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
206206
MethodInfo = new global::TUnit.Core.MethodMetadata
207207
{
208208
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
@@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
252252
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
253253
new InstanceHookMethod
254254
{
255-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
255+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
256256
MethodInfo = new global::TUnit.Core.MethodMetadata
257257
{
258258
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
@@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
302302
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
303303
new InstanceHookMethod
304304
{
305-
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
305+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
306306
MethodInfo = new global::TUnit.Core.MethodMetadata
307307
{
308308
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),

TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
3535
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)].Add(
3636
new InstanceHookMethod
3737
{
38-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
38+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
3939
MethodInfo = new global::TUnit.Core.MethodMetadata
4040
{
4141
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
@@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
7777
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)].Add(
7878
new InstanceHookMethod
7979
{
80-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
80+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
8181
MethodInfo = new global::TUnit.Core.MethodMetadata
8282
{
8383
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
@@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
119119
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)].Add(
120120
new InstanceHookMethod
121121
{
122-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
122+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
123123
MethodInfo = new global::TUnit.Core.MethodMetadata
124124
{
125125
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
@@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
161161
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
162162
new InstanceHookMethod
163163
{
164-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
164+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
165165
MethodInfo = new global::TUnit.Core.MethodMetadata
166166
{
167167
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
@@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
202202
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
203203
new InstanceHookMethod
204204
{
205-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
205+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
206206
MethodInfo = new global::TUnit.Core.MethodMetadata
207207
{
208208
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
@@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
252252
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
253253
new InstanceHookMethod
254254
{
255-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
255+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
256256
MethodInfo = new global::TUnit.Core.MethodMetadata
257257
{
258258
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
@@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
302302
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
303303
new InstanceHookMethod
304304
{
305-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
305+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
306306
MethodInfo = new global::TUnit.Core.MethodMetadata
307307
{
308308
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),

TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
3535
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase1)].Add(
3636
new InstanceHookMethod
3737
{
38-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
38+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
3939
MethodInfo = new global::TUnit.Core.MethodMetadata
4040
{
4141
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
@@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
7777
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase2)].Add(
7878
new InstanceHookMethod
7979
{
80-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
80+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
8181
MethodInfo = new global::TUnit.Core.MethodMetadata
8282
{
8383
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
@@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
119119
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase3)].Add(
120120
new InstanceHookMethod
121121
{
122-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
122+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
123123
MethodInfo = new global::TUnit.Core.MethodMetadata
124124
{
125125
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
@@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
161161
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
162162
new InstanceHookMethod
163163
{
164-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
164+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
165165
MethodInfo = new global::TUnit.Core.MethodMetadata
166166
{
167167
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
@@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
202202
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
203203
new InstanceHookMethod
204204
{
205-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
205+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
206206
MethodInfo = new global::TUnit.Core.MethodMetadata
207207
{
208208
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
@@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
252252
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
253253
new InstanceHookMethod
254254
{
255-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
255+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
256256
MethodInfo = new global::TUnit.Core.MethodMetadata
257257
{
258258
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
@@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
302302
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
303303
new InstanceHookMethod
304304
{
305-
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
305+
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
306306
MethodInfo = new global::TUnit.Core.MethodMetadata
307307
{
308308
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),

TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
3535
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1)].Add(
3636
new InstanceHookMethod
3737
{
38-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
38+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
3939
MethodInfo = new global::TUnit.Core.MethodMetadata
4040
{
4141
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
@@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
7777
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2)].Add(
7878
new InstanceHookMethod
7979
{
80-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
80+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
8181
MethodInfo = new global::TUnit.Core.MethodMetadata
8282
{
8383
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
@@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
119119
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3)].Add(
120120
new InstanceHookMethod
121121
{
122-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
122+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
123123
MethodInfo = new global::TUnit.Core.MethodMetadata
124124
{
125125
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
@@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
161161
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
162162
new InstanceHookMethod
163163
{
164-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
164+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
165165
MethodInfo = new global::TUnit.Core.MethodMetadata
166166
{
167167
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
@@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
202202
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
203203
new InstanceHookMethod
204204
{
205-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
205+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
206206
MethodInfo = new global::TUnit.Core.MethodMetadata
207207
{
208208
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
@@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
252252
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
253253
new InstanceHookMethod
254254
{
255-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
255+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
256256
MethodInfo = new global::TUnit.Core.MethodMetadata
257257
{
258258
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
@@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
302302
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
303303
new InstanceHookMethod
304304
{
305-
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
305+
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
306306
MethodInfo = new global::TUnit.Core.MethodMetadata
307307
{
308308
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),

TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
3535
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
3636
new InstanceHookMethod
3737
{
38-
ClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
38+
InitClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
3939
MethodInfo = new global::TUnit.Core.MethodMetadata
4040
{
4141
Type = typeof(global::TUnit.TestProject.DisposableFieldTests),
@@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
7777
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
7878
new InstanceHookMethod
7979
{
80-
ClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
80+
InitClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
8181
MethodInfo = new global::TUnit.Core.MethodMetadata
8282
{
8383
Type = typeof(global::TUnit.TestProject.DisposableFieldTests),

TUnit.Core.SourceGenerator/CodeGenerators/Writers/Hooks/TestHooksWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void Execute(ICodeWriter sourceBuilder, HooksDataModel model)
3939

4040
sourceBuilder.Append("new global::TUnit.Core.Hooks.InstanceHookMethod");
4141
sourceBuilder.Append("{");
42-
sourceBuilder.Append($"ClassType = typeof({model.FullyQualifiedTypeName}),");
42+
sourceBuilder.Append($"InitClassType = typeof({model.FullyQualifiedTypeName}),");
4343
sourceBuilder.Append("MethodInfo = ");
4444
SourceInformationWriter.GenerateMethodInformation(sourceBuilder, model.Context.SemanticModel.Compilation, model.ClassType, model.Method, null, ',');
4545

TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ private static void GenerateHookObject(CodeWriter writer, HookMethodMetadata hoo
803803

804804
if (isInstance)
805805
{
806-
writer.AppendLine($"ClassType = typeof({hook.TypeSymbol.GloballyQualified()}),");
806+
writer.AppendLine($"InitClassType = typeof({hook.TypeSymbol.GloballyQualified()}),");
807807
}
808808

809809
writer.Append("MethodInfo = ");

TUnit.Core/Attributes/TestMetadata/TimeoutAttribute.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace TUnit.Core;
3232
/// </code>
3333
/// </example>
3434
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
35-
public class TimeoutAttribute(int timeoutInMilliseconds) : TUnitAttribute, ITestDiscoveryEventReceiver, IScopedAttribute<TimeoutAttribute>
35+
public class TimeoutAttribute(int timeoutInMilliseconds) : TUnitAttribute, ITestDiscoveryEventReceiver, IHookRegisteredEventReceiver, IScopedAttribute<TimeoutAttribute>
3636
{
3737
/// <inheritdoc />
3838
public int Order => 0;
@@ -49,4 +49,11 @@ public ValueTask OnTestDiscovered(DiscoveredTestContext context)
4949
context.TestDetails.Timeout = Timeout;
5050
return default(ValueTask);
5151
}
52+
53+
/// <inheritdoc />
54+
public ValueTask OnHookRegistered(HookRegisteredContext context)
55+
{
56+
context.Timeout = Timeout;
57+
return default(ValueTask);
58+
}
5259
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using TUnit.Core.Hooks;
2+
3+
namespace TUnit.Core;
4+
5+
/// <summary>
6+
/// Context for hook registration phase
7+
/// </summary>
8+
public class HookRegisteredContext
9+
{
10+
private TimeSpan? _timeout;
11+
12+
public HookMethod HookMethod { get; }
13+
public string HookName => HookMethod.Name;
14+
15+
/// <summary>
16+
/// Gets or sets the timeout for this hook
17+
/// </summary>
18+
public TimeSpan? Timeout
19+
{
20+
get => _timeout;
21+
set => _timeout = value;
22+
}
23+
24+
public HookRegisteredContext(HookMethod hookMethod)
25+
{
26+
HookMethod = hookMethod;
27+
}
28+
}

0 commit comments

Comments
 (0)