Make NodeStateCollectionConcurrencyTests more robust #2594
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.