Skip to content

[Foundation] Make BuildContext's cancellation handlers testable #545

Description

@ChrisonSimtian

Follow-up from #451 (FT-2, #307).

Problem

BuildContext.RegisterCancellationHandler / UnregisterCancellationHandler — the two methods BuildManager.CancellationHandler exists to delegate to — have no positive coverage. The only spec on the facade (Cancellation_handler_facade_is_a_no_op_without_an_active_context) exercises the null-context path.

They can't be tested as written: registered handlers only run from the Console.CancelKeyPress subscription, and ConsoleCancelEventArgs has no public constructor, so the event can't be raised from a spec.

Outcome

A registered handler can be shown to run, and an unregistered one shown not to, without depending on a real Ctrl+C.

Needs a seam — e.g. an internal void InvokeCancellationHandlers() on BuildContext that the CancelKeyPress subscription calls, so specs can drive the same path. Worth settling before FT-4/5/6 move more per-run services onto the context.

Acceptance criteria

  • Registering through BuildManager.CancellationHandler with an active context runs the handler when cancellation is signalled.
  • Unregistering stops it running.
  • Handlers registered against one context don't run for another.
  • The seam stays internal — no InternalsVisibleTo to non-test assemblies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions