Skip to content

Commit

Permalink
[chore] Add test for on startup compaction (#33511)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
While there are
[tests](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/extension/storage/filestorage/client_test.go#L214)
for `OnRebound` compaction, I didn't spot any that cover the `OnStart`
option. This PR adds a unit test for this case.

**Link to tracking Issue:** <Issue number if applicable> ~

**Testing:** <Describe what testing was performed and which tests were
added.> Added

**Documentation:** <Describe the documentation added.> ~

Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark authored Jun 13, 2024
1 parent 6c15654 commit 2d661a7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions extension/storage/filestorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension/experimental/storage"
"go.opentelemetry.io/collector/extension/extensiontest"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
)

func TestExtensionIntegrity(t *testing.T) {
Expand Down Expand Up @@ -485,3 +487,41 @@ func TestCleanupOnStart(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(files))
}

func TestCompactionOnStart(t *testing.T) {
ctx := context.Background()

logCore, logObserver := observer.New(zap.DebugLevel)
logger := zap.New(logCore)
set := extensiontest.NewNopSettings()
set.Logger = logger

tempDir := t.TempDir()
temp, _ := os.CreateTemp(tempDir, TempDbPrefix)
temp.Close()

f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
cfg.Directory = tempDir
cfg.Compaction.Directory = tempDir
cfg.Compaction.OnStart = true
extension, err := f.CreateExtension(context.Background(), set, cfg)
require.NoError(t, err)

se, ok := extension.(storage.Extension)
require.True(t, ok)
require.NoError(t, se.Start(ctx, componenttest.NewNopHost()))

client, err := se.GetClient(
ctx,
component.KindReceiver,
newTestEntity("my_component"),
"",
)
require.NoError(t, err)
t.Cleanup(func() {
// At least one compaction should have happened on start
require.GreaterOrEqual(t, len(logObserver.FilterMessage("finished compaction").All()), 1)
require.NoError(t, client.Close(context.TODO()))
})
}

0 comments on commit 2d661a7

Please sign in to comment.