Skip to content

Extend [Timeout] to cover hooks, object initializers, and broader scopes #4789

@thomhurst

Description

@thomhurst

Problem

[Timeout] currently only applies to test body execution. Hooks and object initializers have no timeout protection — a misbehaving [Before(HookType.Assembly)] or IAsyncInitializer.InitializeAsync() that hangs will block the entire test run indefinitely.

Goal

Make [Timeout] much more powerful — it should be applicable to:

  1. Test body (current behavior)
  2. Hooks[Before] / [After] at all scopes (Test, Class, Assembly, Session, Discovery)
  3. Object initializersIAsyncInitializer.InitializeAsync() implementations
  4. Broader scopes — e.g. [Timeout] on an assembly meaning "the entire test run must complete within X"

Design Questions

  • How does [Timeout] on a class interact with [Timeout] on individual tests? Is it a total budget for the class, or a default for each test?
  • Assembly-level [Timeout] — is it a hard cap on the entire assembly's execution time? What happens to in-flight tests when it fires?
  • Hook timeouts — should they inherit from the scope they belong to (e.g. a class-level hook inherits the class timeout), or require explicit configuration?
  • Should individual hooks be able to opt out of a scope-level timeout?
  • How does this interact with [Retry]? Does each retry get a fresh timeout, or does the timeout cover all retries?
  • Object initializer timeouts — should they be separate from the test timeout, or part of it? (Currently data source init runs outside the test timeout)

Notes

  • Requires careful design before implementation
  • Some aspects may be breaking (changing what [Timeout] on a class means)
  • Deferred to v2

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingv2Deferred to v2 release

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions