Skip to content

Commit

Permalink
Revert incorrectly merged cache_test.go file
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Feb 6, 2024
1 parent 4f97427 commit a532a58
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions pkg/storage/stores/shipper/bloomshipper/cache_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bloomshipper

import (
"os"
"testing"
"time"

Expand All @@ -10,50 +9,53 @@ import (
"go.uber.org/atomic"
)

func Test_CachedBlock(t *testing.T) {
func TestBlockDirectory_Cleanup(t *testing.T) {
checkInterval := 50 * time.Millisecond
timeout := 200 * time.Millisecond

tests := map[string]struct {
releaseQuerier bool
expectDirectoryToBeDeletedWithin time.Duration
}{
"expected block directory to be removed once all queriers are released": {
releaseQuerier: true,
// four times grater than activeQueriersCheckInterval
expectDirectoryToBeDeletedWithin: 200 * time.Millisecond,
"expect directory to be removed once all queriers are released": {
releaseQuerier: true,
expectDirectoryToBeDeletedWithin: 2 * checkInterval,
},
"expected block directory to be force removed after timeout": {
releaseQuerier: false,
// four times grater than removeDirectoryTimeout
expectDirectoryToBeDeletedWithin: 2 * time.Second,
"expect directory to be force removed after timeout": {
releaseQuerier: false,
expectDirectoryToBeDeletedWithin: 2 * timeout,
},
}
for name, testData := range tests {
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
extractedBlockDirectory := t.TempDir()
blockFilePath, _, _, _ := createBlockArchive(t)
err := extractArchive(blockFilePath, extractedBlockDirectory)
require.NoError(t, err)
require.DirExists(t, extractedBlockDirectory)

cached := BlockDirectory{
blockDir := BlockDirectory{
Path: extractedBlockDirectory,
removeDirectoryTimeout: 500 * time.Millisecond,
activeQueriersCheckInterval: 50 * time.Millisecond,
logger: log.NewLogfmtLogger(os.Stderr),
refCount: atomic.NewInt32(1),
removeDirectoryTimeout: timeout,
activeQueriersCheckInterval: checkInterval,
logger: log.NewNopLogger(),
refCount: atomic.NewInt32(0),
}
cached.removeDirectoryAsync()
//ensure directory exists
require.Never(t, func() bool {
return directoryDoesNotExist(extractedBlockDirectory)
}, 200*time.Millisecond, 50*time.Millisecond)
// acquire directory
blockDir.refCount.Inc()
// start cleanup goroutine
blockDir.removeDirectoryAsync()

if testData.releaseQuerier {
cached.refCount.Dec()
if tc.releaseQuerier {
// release directory
blockDir.refCount.Dec()
}
//ensure directory does not exist

// ensure directory does not exist any more
require.Eventually(t, func() bool {
return directoryDoesNotExist(extractedBlockDirectory)
}, testData.expectDirectoryToBeDeletedWithin, 50*time.Millisecond)
}, tc.expectDirectoryToBeDeletedWithin, 10*time.Millisecond)
})
}
}
Expand All @@ -72,7 +74,7 @@ func Test_ClosableBlockQuerier(t *testing.T) {

querier := blockDir.BlockQuerier()
require.Equal(t, int32(1), blockDir.refCount.Load())
querier.Close()
require.NoError(t, querier.Close())
require.Equal(t, int32(0), blockDir.refCount.Load())

}

0 comments on commit a532a58

Please sign in to comment.