Skip to content

Commit d337ba6

Browse files
authored
fix: Retry the file deletion to prevent flakies for issue #938 (#1076)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved reliability of automated tests by moving cleanup to test teardown, adding retry-based deletion and clearer failure reporting. * Reduces flakiness (notably on Windows) and improves stability in CI and local runs. * No changes to application features, behavior, performance, or compatibility; end users will not observe functional differences. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a07eac0 commit d337ba6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/internal/handle_file_operation_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ func TestCompressSelectedFiles(t *testing.T) {
141141
p.SendKey(common.Hotkeys.ExtractFile[0])
142142
// File extraction is supposedly async. So function's return doesn't means its done.
143143
extractedDir := filepath.Join(tt.startDir, tt.extractedDirName)
144+
145+
// Setup cleanup to run even if test fails
146+
t.Cleanup(func() {
147+
cleanupWithRetry := func(path, label string) {
148+
var lastErr error
149+
ok := assert.Eventually(t, func() bool {
150+
lastErr = os.RemoveAll(path)
151+
return lastErr == nil
152+
}, DefaultTestTimeout, DefaultTestTick)
153+
if !ok {
154+
t.Fatalf("Failed to remove %s %q: %v", label, path, lastErr)
155+
}
156+
}
157+
cleanupWithRetry(extractedDir, "extracted directory")
158+
cleanupWithRetry(zipFile, "zip file")
159+
})
144160
assert.Eventually(t, func() bool {
145161
for _, f := range tt.expectedFilesAfterExtract {
146162
_, err := os.Stat(filepath.Join(extractedDir, f))
@@ -151,9 +167,6 @@ func TestCompressSelectedFiles(t *testing.T) {
151167
return true
152168
}, DefaultTestTimeout, DefaultTestTick, "Extraction of files failed Required - [%s]+%v",
153169
extractedDir, tt.expectedFilesAfterExtract)
154-
155-
require.NoError(t, os.RemoveAll(extractedDir))
156-
require.NoError(t, os.RemoveAll(zipFile))
157170
})
158171
}
159172

0 commit comments

Comments
 (0)