@@ -1289,6 +1289,58 @@ func TestStorageOperations(t *testing.T) {
12891289 assert .ErrorIs (t , err , ErrNotFound )
12901290}
12911291
1292+ func TestRemoveAllWithRetryRetriesDirectoryNotEmpty (t * testing.T ) {
1293+ t .Parallel ()
1294+
1295+ path := "/tmp/test-instance"
1296+ attempts := 0
1297+ var slept []time.Duration
1298+
1299+ err := removeAllWithRetry (path , func (got string ) error {
1300+ attempts ++
1301+ require .Equal (t , path , got )
1302+ if attempts <= 3 {
1303+ return & os.PathError {Op : "unlinkat" , Path : got , Err : syscall .ENOTEMPTY }
1304+ }
1305+ return nil
1306+ }, func (d time.Duration ) {
1307+ slept = append (slept , d )
1308+ })
1309+
1310+ require .NoError (t , err )
1311+ assert .Equal (t , 4 , attempts )
1312+ assert .Equal (t , []time.Duration {
1313+ 10 * time .Millisecond ,
1314+ 20 * time .Millisecond ,
1315+ 40 * time .Millisecond ,
1316+ }, slept )
1317+ }
1318+
1319+ func TestRemoveAllWithRetryStopsAfterMaxRetries (t * testing.T ) {
1320+ t .Parallel ()
1321+
1322+ attempts := 0
1323+ var slept []time.Duration
1324+
1325+ err := removeAllWithRetry ("/tmp/test-instance" , func (string ) error {
1326+ attempts ++
1327+ return & os.PathError {Op : "unlinkat" , Path : "/tmp/test-instance" , Err : syscall .ENOTEMPTY }
1328+ }, func (d time.Duration ) {
1329+ slept = append (slept , d )
1330+ })
1331+
1332+ require .Error (t , err )
1333+ assert .ErrorIs (t , err , syscall .ENOTEMPTY )
1334+ assert .Equal (t , deleteInstanceDataMaxRetries + 1 , attempts )
1335+ assert .Equal (t , []time.Duration {
1336+ 10 * time .Millisecond ,
1337+ 20 * time .Millisecond ,
1338+ 40 * time .Millisecond ,
1339+ 80 * time .Millisecond ,
1340+ 100 * time .Millisecond ,
1341+ }, slept )
1342+ }
1343+
12921344func TestStandbyAndRestore (t * testing.T ) {
12931345 t .Parallel ()
12941346 // Require KVM access (don't skip, fail informatively)
0 commit comments