test(store): ensure busy manager goroutine is finished (#15788)
## Description
Without this change, there were intermittent failures due to a non-empty t.TempDir() directory at the end of a test:
```console
$ go test -run=LoadChunk$ ./snapshots/ -count=220 -failfast
--- FAIL: TestManager_LoadChunk (0.01s)
testing.go:1225: TempDir RemoveAll cleanup: unlinkat /var/folders/.../T/TestManager_LoadChunk1472891739/001: directory not empty
FAIL
FAIL cosmossdk.io/store/snapshots 0.177s
```
With this change, I can no longer reproduce the flaky failure:
```console
$ go test -run=LoadChunk$ ./snapshots/ -count=1000 -failfast
ok cosmossdk.io/store/snapshots 15.722s
```
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] confirmed that this PR does not change production code
This commit is contained in:
parent
f95585b40d
commit
0b09920c0a
@ -181,13 +181,24 @@ func setupBusyManager(t *testing.T) *snapshots.Manager {
|
||||
mgr := snapshots.NewManager(store, opts, hung, nil, log.NewNopLogger())
|
||||
require.Equal(t, opts.Interval, hung.snapshotInterval)
|
||||
|
||||
// Channel to ensure the test doesn't finish until the goroutine is done.
|
||||
// Without this, there are intermittent test failures about
|
||||
// the t.TempDir() cleanup failing due to the directory not being empty.
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
defer close(done)
|
||||
_, err := mgr.Create(1)
|
||||
require.NoError(t, err)
|
||||
_, didPruneHeight := hung.prunedHeights[1]
|
||||
require.True(t, didPruneHeight)
|
||||
}()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
t.Cleanup(func() {
|
||||
<-done
|
||||
})
|
||||
|
||||
t.Cleanup(hung.Close)
|
||||
|
||||
return mgr
|
||||
|
||||
Loading…
Reference in New Issue
Block a user