fix(TestCache): eliminate hanging Windows tests #978
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.
As seen on PR #933 and others, it's common for the Windows test suite to fail when run via GitHub Actions. In that PR, @zinderic also noted that it's less prevalent but can also occur on Mac OSX.
I can't test on Mac OSX but on the
ext4
file system, theTempDir
is deleted but it's asynchronous and only occurs when there are no open file handles (when thego test ./...
ends). On Windows, removing the temporary directory is (more?) synchronous and so Go waits for the OS to remove theTempDir
while the OS is waiting for the open file handlers to be closed.As seen in the changed file, the solution is to explicitly close both instances of the cache as soon as they're no longer needed. I don't quite understand why the other cache tests don't have this problem but my intuition says that the tests would run faster if those caches were also explicitly closed.
I'm considering refactoring these tests a bit so that there's a
t.Helper()
to create and clean-up the caches being tested - what do you think?