CGI-FR / IoT-Hub-Portal

IoT Hub Portal is a solution for handling IoT Devices easily. It leverages on Azure IoT Hub / AWS IoT Core for connectivity and device management.
https://cgi-fr.github.io/IoT-Hub-Portal/stable/
MIT License
32 stars 11 forks source link

Feature: Avoid usage of Thread.Sleep on Blazor unit tests #818

Closed hocinehacherouf closed 2 years ago

hocinehacherouf commented 2 years ago

Is your feature request related to a problem? Please describe. On blazor unit tests, when we call RenderComponent, async calls in the render are not waited. We use Thread.Sleep to wait an amount of time, without any guaranty that async calls are finished.

The usage of Thread.Sleep in unit tests produces random failures on CI pipelines.

Describe the solution you'd like Replace the usage Thread.Sleep by:

Theses methods will block only the thread of test, not the rendrer and wait until the predicate/assertion passes or timeout.

Examples:

cut.WaitForAssertion(() => cut.Find("form").Should().NotBeNull());
cut.WaitForAssertion(() => this.mockRepository.VerifyAll());

Remark: The default timeout of the this methods is 1 second. We can change the value of this default timeout.

Additional context See also https://github.com/bUnit-dev/bUnit/issues/60

audserraCGI commented 2 years ago

FYI @hocinehacherouf, I started working on DeviceModelPages

audserraCGI commented 2 years ago

I'm done with DeviceModelPages, I am now going to work on DevicePages, @hocinehacherouf ! 😄