Class RegistrationWaitExtensions
- Namespace
- Cratis.Chronicle.Registrations
- Assembly
- Cratis.Chronicle.dll
Helper extensions providing wait methods for artifact registration.
public static class RegistrationWaitExtensions
- Inheritance
-
RegistrationWaitExtensions
- Inherited Members
Remarks
These extensions are very useful for integration testing purposes, and for anything that has to treat "the read side is up" as a fact before it measures anything.
Methods
WaitForRegistration(IEventStore, TimeSpan?)
Wait for artifact registration to have run for the event store, with an optional timeout.
public static Task<RegistrationOutcome> WaitForRegistration(this IEventStore eventStore, TimeSpan? timeout = null)
Parameters
eventStoreIEventStoreEvent store to wait for.
timeoutTimeSpan?Optional timeout. If none is provided, it will default to 5 seconds.
Returns
- Task<RegistrationOutcome>
The RegistrationOutcome observed once registration had run.
Remarks
Registration is a handler on the connection lifecycle, so from outside "has not run yet" and "never ran" look identical - this is what tells them apart. It waits for registration to have run, not to have succeeded: the returned outcome still has to be asked whether every artifact registered. If registration is running again, or a disconnect has scheduled re-registration on reconnect, it waits for that run rather than returning the previous outcome.
For newly registered active projections, a successful outcome means the kernel has registered their artifacts and subscribed their observers in the event store's existing namespaces. It does not mean that events appended afterwards are already reflected in materialized read models. For read-your-writes, use WaitForCompletion(IAppendResultForObserverCompletion, TimeSpan?) on the append result before reading, or use a passive read model.
A run that failed returns here too, carrying its Failure - the timeout is for a registration that never finished, not for one that finished badly. Ask RegistrationOutcome what happened rather than reading a returned value as success.
Do not wait on IsConnected instead. That flag is set to true before the connected handlers - registration among them - have run, and only rolled back once they have all finished, so a poll of it can return while registration is still in flight. See RegistrationOutcome.
Exceptions
- TaskCanceledException
Thrown when registration has not run within the timeout.