Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use backoff in time machine test to reduce flakiness (hopefully) #1625

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions ee/agent/timemachine/timemachine_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package timemachine

import (
"context"
"fmt"
"os"
"os/user"
"path/filepath"
Expand All @@ -14,6 +15,7 @@ import (

"github.com/kolide/launcher/ee/agent/types/mocks"
"github.com/kolide/launcher/ee/allowedcmd"
"github.com/kolide/launcher/pkg/backoff"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -85,22 +87,34 @@ func TestAddExclusions(t *testing.T) {
// we've seen some flake in CI here where the exclusions have not been
// updated by the time we perform assertions, so sleep for a bit to give
// OS some time to catch up
time.Sleep(3 * time.Second)
time.Sleep(1 * time.Second)

// ensure the files are included / excluded as expected
for fileName, shouldBeExcluded := range shouldBeExcluded {
cmd, err := allowedcmd.Tmutil(context.TODO(), "isexcluded", filepath.Join(testDir, fileName))
require.NoError(t, err)

out, err := cmd.CombinedOutput()
require.NoError(t, err)

if shouldBeExcluded {
require.Contains(t, string(out), "[Excluded]")
continue
}

// should be included
require.Contains(t, string(out), "[Included]")
// Allow for a couple retries for the file to show up as excluded appropriately --
// we've seen this be a little flaky in CI
err := backoff.WaitFor(func() error {
cmd, err := allowedcmd.Tmutil(context.TODO(), "isexcluded", filepath.Join(testDir, fileName))
if err != nil {
return fmt.Errorf("creating tmutil command: %w", err)
}

out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running tmutil isexcluded: %w", err)
}

if shouldBeExcluded && !strings.Contains(string(out), "[Excluded]") {
return fmt.Errorf("output `%s` does not contain [Excluded], but file should be excluded", string(out))
}

if !shouldBeExcluded && !strings.Contains(string(out), "[Included]") {
return fmt.Errorf("output `%s` does not contain [Included], but file should be included", string(out))
}

return nil
}, 1*time.Second, 200*time.Millisecond)

require.NoError(t, err, "file not handled as expected")
}
}
Loading