Summary
Some extensions may not be implementable using the current extensibility model of MTP.
For example, an extension might want to start and complete a specific piece of work and guarantee that it happens before the test starts.
Currently, the only option is to implement IDataConsumer and process TestNodeUpdateMessage with in-progress state in ConsumeAsync. But, due to the async nature of message bus, there is no guarantee that the test isn't already started by the time ConsumeAsync is called.
Proposed Feature
-
Introduce a new IBlockingDataConsumer interface.
public interface IBlockingDataConsumer : ITestHostExtension
{
Type[] DataTypesConsumed { get; }
bool IsInterestingData(IData value);
Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationToken cancellationToken);
}
-
Add a new extensibility point to register blocking data consumers. Users should be able to do builder.TestHost.AddBlockingDataConsumer(serviceProvider => new MyBlockingDataConsumer(serviceProver))
-
The implementation of IMessageBus.PublishAsync should consider such data consumers. When the data is published, it needs to be immediately be consumed.
-
The IsInterestingData is a perf optimization. We don't want such blocking extension to slow us down for every data type being consumed (e.g, TestNodeUpdateMessage). Instead, only block when it's really interested in this specific TestNodeUpdateMessage (e.g, it has in-progress state)
-
If the data being published is not interesting for any registered IBlockingDataConsumer (or there are no registered IBlockingDataConsumers at all), we maintain today's behavior.
Summary
Some extensions may not be implementable using the current extensibility model of MTP.
For example, an extension might want to start and complete a specific piece of work and guarantee that it happens before the test starts.
Currently, the only option is to implement
IDataConsumerand process TestNodeUpdateMessage with in-progress state inConsumeAsync. But, due to the async nature of message bus, there is no guarantee that the test isn't already started by the timeConsumeAsyncis called.Proposed Feature
Introduce a new
IBlockingDataConsumerinterface.Add a new extensibility point to register blocking data consumers. Users should be able to do
builder.TestHost.AddBlockingDataConsumer(serviceProvider => new MyBlockingDataConsumer(serviceProver))The implementation of
IMessageBus.PublishAsyncshould consider such data consumers. When the data is published, it needs to be immediately be consumed.The
IsInterestingDatais a perf optimization. We don't want such blocking extension to slow us down for every data type being consumed (e.g, TestNodeUpdateMessage). Instead, only block when it's really interested in this specific TestNodeUpdateMessage (e.g, it has in-progress state)If the data being published is not interesting for any registered IBlockingDataConsumer (or there are no registered
IBlockingDataConsumers at all), we maintain today's behavior.