Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NodeStateCollectionConcurrencyTests more robust #2594

Conversation

saurla
Copy link
Contributor

@saurla saurla commented Apr 23, 2024

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

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

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.

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mregen
Copy link
Contributor

mregen commented Apr 25, 2024

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

@saurla
Copy link
Contributor Author

saurla commented Apr 25, 2024

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.

@mregen mregen added this to the April Update milestone Apr 25, 2024
@mregen mregen merged commit 9cd4536 into OPCFoundation:master May 1, 2024
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky build due to NodeState concurrency tests
2 participants