C#C
C#3y ago
Pacyfist

❔ Timing issues whole end-to-end testing microservices.

I'm using MassTransit to communicate between microservies. This creates a problem when I'm writing tests. This is my test written using SpecFlow BDD framework:

Scenario: Add one task and check if it was created
    Given a real microservice Tested.API
    When a BasicTask is added for installation "9D68A95D-D5AF-4255-8D28-35A3BD8019CC"
    Then count of all tasks for installation "9D68A95D-D5AF-4255-8D28-35A3BD8019CC" should be 1


And it works perfectly. A single message is sent, and processed. But when the case is more complex there is a problem.

Scenario: Add bulk tasks and check if they were created
    Given a real microservice Tested.API
    When a BasicTask are added in bulk for installations
        | InstallationIds                      |
        | 9D68A95D-D5AF-4255-8D28-35A3BD8019CC |
        | 81A4A87E-2D12-49E0-8E85-25AD8E17B1A5 |
    Then count of all tasks for installation "9D68A95D-D5AF-4255-8D28-35A3BD8019CC" should be 1
    And count of all tasks for installation "81A4A87E-2D12-49E0-8E85-25AD8E17B1A5" should be 1


Here scenario fails, because the message adding the task for installation 81A4A87E-2D12-49E0-8E85-25AD8E17B1A5 is processed after the check has already been run.

Is there a way to ensure that messages were processed using MassTransit TestHarness? ChatGPT is fixated on simply adding await Task.Delay(1000) and I would feel really dirty doing that.
Was this page helpful?