Fix reliability of a couple of caching tests #359
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.
These tests relied on some timing for file writes and static property access. This causes a race condition where the change monitor is disposed at some point internally, but at the same time the test tries to dispose it. This causes the list of change monitors to be enumerated/modified at the same time leading to a crash. The following are fixes/mitigations:
This also changed the IHttpRuntime access to go through HttpContext.Current instead of a static property. While not necessary for the current bug, it has been the source of other issues where a test will set the static property at the same time another test is using it. Switching to HttpContext.Current will prevent similar issues as the IHttpRuntime will be request/test local.