OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.94k stars 942 forks source link

Make NodeStateCollectionConcurrencyTests more robust #2594

Closed saurla closed 5 months ago

saurla commented 5 months ago

Made tests more robust by using GetConsumingEnumerable which blocks indefinitely.

Proposed changes

These changes aim to make the NodeStateCollectionConcurrencyTests to not randomly fail in the CI build.

Related Issues

Types of changes

Checklist

Further comments

I'm not 100% sure that this fixes the flaky CI builds since I was not able to reproduce the issue without modifying the test code. My assumption is that the test fails because I was calling TryTake on the BlockingCollection with timeout of 1 second. Maybe in some cases in the CI system there is some slowness that causes the other Task which is adding items to the collection to take more than 1 second. In this case the TryTake returns false and while loop is exited and then the items from the BlockingCollection are never removed.

I was able to reproduce the issue by adding a 1 second Thread.Sleep at the begin of the Task that adds items to the collection. I fixed this issue by using GetConsumingEnumerable instead of TryTake. The GetConsumingEnumerable block indefinitely so there is no danger of some slowness to fail the build. Since I'm using indefinite blocking I added timeout to each of the tests so that they don't take too long in case something goes wrong in the test.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 52.21%. Comparing base (60689c9) to head (79046fe).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2594 +/- ## ========================================== - Coverage 54.62% 52.21% -2.42% ========================================== Files 342 290 -52 Lines 65082 58476 -6606 Branches 13350 11926 -1424 ========================================== - Hits 35553 30531 -5022 + Misses 25661 24482 -1179 + Partials 3868 3463 -405 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mregen commented 5 months ago

thanks @saurla for the improvement, please check if there is a using missing for the CancellationToken to fix the build.

saurla commented 5 months ago

Sure, my bad. I had some Thread.Sleep in my code for testing purposes so I thought the using was just for that. I have now committed the missing using.