test: Fix flakiness of TestGetRemotes #6099
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.
Found in #6092
https://github.com/moby/buildkit/actions/runs/16344069969/job/46175402958?pr=6092#step:8:4328
This is caused by the following part of test in TestGetRemotes isn't thread safe.
buildkit/cache/manager_test.go
Lines 1773 to 1788 in f7607f3
Concretely, the following sequence can occur.
r.isLazy()GetRemotes()of another goroutine, because that function can unlazy the blob.r.getBlobWithCompression()matches to the earlierr.isLazy()call. But the laziness was changed by other goroutine so the test fails.This isn't a bug of the cache but is a bug in the test. this PR fixes this flakiness by adding a mutex to protect the part of the test.
Although the failure rate wasn't high (about 1/200 when I run the test during debugging #6092), this can be reproduced by forcing the timing shown in the above steps (c.f. ktock@1ddcea9), which can be fixed by the same change as this PR (c.f. ktock@522d82a).