Skip to content

[Feature]: Blocking data consumers #6529

@Youssef1313

Description

@Youssef1313

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

  1. Introduce a new IBlockingDataConsumer interface.

    public interface IBlockingDataConsumer : ITestHostExtension
    {
        Type[] DataTypesConsumed { get; }
    
        bool IsInterestingData(IData value);
    
        Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationToken cancellationToken);
    }
  2. Add a new extensibility point to register blocking data consumers. Users should be able to do builder.TestHost.AddBlockingDataConsumer(serviceProvider => new MyBlockingDataConsumer(serviceProver))

  3. The implementation of IMessageBus.PublishAsync should consider such data consumers. When the data is published, it needs to be immediately be consumed.

  4. 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)

  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions