IBlockingDataConsumer Interface

Definition

Marker interface for a IDataConsumer that must consume the data inline, before the call to publish the data returns to the producer.

public interface IBlockingDataConsumer : Microsoft.Testing.Platform.Extensions.IDataConsumer
type IBlockingDataConsumer = interface
    interface IDataConsumer
    interface IExtension
Public Interface IBlockingDataConsumer
Implements IDataConsumer
Implements

Remarks

A regular IDataConsumer consumes data asynchronously: the data is queued and processed on a background loop, so there is no guarantee about when ConsumeAsync(IDataProducer, IData, CancellationToken) runs relative to the producer continuing its work. A consumer that additionally implements IBlockingDataConsumer is instead invoked inline by the message bus, so the producer's call to publish does not return until ConsumeAsync(IDataProducer, IData, CancellationToken) has completed. This is useful for extensions that need to guarantee a piece of work happens before the producer proceeds (for example, before a test starts running).

Because consumption happens inline, any exception thrown by ConsumeAsync(IDataProducer, IData, CancellationToken) propagates back to the producer that published the data, rather than being observed later during drain. Implementations should therefore avoid throwing for non-fatal conditions.

Inline consumption is serialized: only one ConsumeAsync(IDataProducer, IData, CancellationToken) call runs at a time per consumer. As a consequence, a blocking consumer must not, from within its ConsumeAsync(IDataProducer, IData, CancellationToken), publish data that is routed back to itself, as that would deadlock. Note that publishing data where the producer is the consumer itself (same UID) is safe, because the message bus skips delivering a producer's data back to that same producer; the deadlock risk is specifically re-entrant publishing that routes back to this consumer under a different producer UID.

Properties

Name Description
DataTypesConsumed

Gets the types of data consumed by the data consumer.

(Inherited from IDataConsumer)
Description

Gets the description of the extension.

(Inherited from IExtension)
DisplayName

Gets the display name of the extension.

(Inherited from IExtension)
Uid

Gets the unique identifier for the extension.

(Inherited from IExtension)
Version

Gets the version of the extension (ideally semantic version).

(Inherited from IExtension)

Methods

Name Description
ConsumeAsync(IDataProducer, IData, CancellationToken)

Consumes the specified data produced by a data producer.

(Inherited from IDataConsumer)
IsEnabledAsync()

Controls whether the extension is enabled or not. This is useful for extensions that are always registered but only enabled when certain conditions are met. For example, an extension that would want to be run only when its associated command line option is provided by the user.

(Inherited from IExtension)

Applies to