@@ -99,13 +99,13 @@ class TestCLIAnonymousVolumes: CLITest {
9999 let ( _, _, _) = ( try ? run ( arguments: args) ) ?? ( " " , " " , 1 )
100100 }
101101
102- @Test func testAnonymousVolumeCreationAndPersistence ( ) async throws {
102+ @Test func testAnonymousVolumeCreationAndAutoCleanup ( ) async throws {
103103 let testName = getTestName ( )
104104 let containerName = " \( testName) _c1 "
105105
106106 defer {
107107 doRemoveIfExists ( name: containerName, force: true )
108- // Clean up anonymous volumes
108+ // Clean up any remaining anonymous volumes
109109 if let volumes = try ? getAnonymousVolumeNames ( ) {
110110 volumes. forEach { doVolumeDeleteIfExists ( name: $0) }
111111 }
@@ -129,7 +129,7 @@ class TestCLIAnonymousVolumes: CLITest {
129129
130130 #expect( status == 0 , " container run should succeed " )
131131
132- // Give time for container removal to complete
132+ // Give time for cleanup to complete
133133 try await Task . sleep ( for: . seconds( 1 ) )
134134
135135 // Verify container was removed
@@ -138,9 +138,9 @@ class TestCLIAnonymousVolumes: CLITest {
138138 . filter { $0. contains ( containerName) }
139139 #expect( containers. isEmpty, " container should be removed with --rm " )
140140
141- // Verify anonymous volume persists (no auto-cleanup)
141+ // Verify anonymous volume was auto-cleaned up
142142 let afterCount = try getAnonymousVolumeNames ( ) . count
143- #expect( afterCount == beforeCount + 1 , " anonymous volume should persist even with --rm " )
143+ #expect( afterCount == beforeCount, " anonymous volume should be auto-cleaned up with --rm " )
144144 }
145145
146146 @Test func testAnonymousVolumePersistenceWithoutRm( ) throws {
@@ -191,43 +191,6 @@ class TestCLIAnonymousVolumes: CLITest {
191191 doVolumeDeleteIfExists ( name: volumeID)
192192 }
193193
194- @Test func testMultipleAnonymousVolumes( ) async throws {
195- let testName = getTestName ( )
196- let containerName = " \( testName) _c1 "
197-
198- defer {
199- doRemoveIfExists ( name: containerName, force: true )
200- // Clean up anonymous volumes
201- if let volumes = try ? getAnonymousVolumeNames ( ) {
202- volumes. forEach { doVolumeDeleteIfExists ( name: $0) }
203- }
204- }
205-
206- let beforeCount = try getAnonymousVolumeNames ( ) . count
207-
208- // Run with multiple anonymous volumes
209- let ( _, _, status) = try run ( arguments: [
210- " run " ,
211- " --rm " ,
212- " --name " ,
213- containerName,
214- " -v " , " /data1 " ,
215- " -v " , " /data2 " ,
216- " -v " , " /data3 " ,
217- alpine,
218- " sh " , " -c " , " ls -d /data* " ,
219- ] )
220-
221- #expect( status == 0 , " container run should succeed " )
222-
223- // Give time for container removal
224- try await Task . sleep ( for: . seconds( 1 ) )
225-
226- // All 3 volumes should persist (no auto-cleanup)
227- let afterCount = try getAnonymousVolumeNames ( ) . count
228- #expect( afterCount == beforeCount + 3 , " all 3 anonymous volumes should persist " )
229- }
230-
231194 @Test func testAnonymousMountSyntax( ) async throws {
232195 let testName = getTestName ( )
233196 let containerName = " \( testName) _c1 "
@@ -255,12 +218,12 @@ class TestCLIAnonymousVolumes: CLITest {
255218
256219 #expect( status == 0 , " container run with --mount should succeed " )
257220
258- // Give time for container removal
259- try await Task . sleep ( for: . seconds( 1 ) )
221+ // Give time for container removal and volume cleanup
222+ try await Task . sleep ( for: . seconds( 2 ) )
260223
261- // Anonymous volume should persist (no auto-cleanup)
224+ // Anonymous volume should be auto-cleaned up with --rm
262225 let afterCount = try getAnonymousVolumeNames ( ) . count
263- #expect( afterCount == beforeCount + 1 , " anonymous volume should persist " )
226+ #expect( afterCount == beforeCount, " anonymous volume should be auto-cleaned up with --rm " )
264227 }
265228
266229 @Test func testAnonymousVolumeUUIDFormat( ) throws {
@@ -394,15 +357,15 @@ class TestCLIAnonymousVolumes: CLITest {
394357
395358 #expect( status == 0 , " container run should succeed " )
396359
397- // Give time for container removal
398- try await Task . sleep ( for: . seconds( 1 ) )
360+ // Give time for container removal and volume cleanup
361+ try await Task . sleep ( for: . seconds( 2 ) )
399362
400363 // Named volume should still exist
401364 let namedExists = try volumeExists ( name: namedVolumeName)
402365 #expect( namedExists, " named volume should persist " )
403366
404367 let afterAnonCount = try getAnonymousVolumeNames ( ) . count
405- #expect( afterAnonCount == beforeAnonCount + 1 , " anonymous volume should persist " )
368+ #expect( afterAnonCount == beforeAnonCount, " anonymous volume should be auto-cleaned up with --rm " )
406369 }
407370
408371 @Test func testAnonymousVolumeManualDeletion( ) throws {
@@ -463,8 +426,8 @@ class TestCLIAnonymousVolumes: CLITest {
463426
464427 #expect( status == 0 , " detached container run should succeed " )
465428
466- // Wait for container to exit
467- try await Task . sleep ( for: . seconds( 3 ) )
429+ // Wait for container to exit and volume cleanup
430+ try await Task . sleep ( for: . seconds( 4 ) )
468431
469432 // Container should be removed
470433 let ( lsOutput, _, _) = try run ( arguments: [ " ls " , " -a " ] )
@@ -473,6 +436,51 @@ class TestCLIAnonymousVolumes: CLITest {
473436 #expect( containers. isEmpty, " container should be auto-removed " )
474437
475438 let afterCount = try getAnonymousVolumeNames ( ) . count
476- #expect( afterCount == beforeCount + 1 , " anonymous volume should persist " )
439+ #expect( afterCount == beforeCount, " anonymous volume should be auto-cleaned up with --rm " )
440+ }
441+
442+ @Test func testMultipleAnonymousVolumesAutoCleanupWithRm( ) async throws {
443+ let testName = getTestName ( )
444+ let containerName = " \( testName) _c1 "
445+
446+ defer {
447+ doRemoveIfExists ( name: containerName, force: true )
448+ // Clean up any remaining anonymous volumes
449+ if let volumes = try ? getAnonymousVolumeNames ( ) {
450+ volumes. forEach { doVolumeDeleteIfExists ( name: $0) }
451+ }
452+ }
453+
454+ let beforeCount = try getAnonymousVolumeNames ( ) . count
455+
456+ // Run container with --rm and 5 anonymous volumes
457+ let ( _, _, status) = try run ( arguments: [
458+ " run " ,
459+ " --rm " ,
460+ " --name " ,
461+ containerName,
462+ " -v " , " /data1 " ,
463+ " -v " , " /data2 " ,
464+ " -v " , " /data3 " ,
465+ " -v " , " /data4 " ,
466+ " -v " , " /data5 " ,
467+ alpine,
468+ " sh " , " -c " , " echo 'test' > /data1/file.txt && cat /data1/file.txt " ,
469+ ] )
470+
471+ #expect( status == 0 , " container run should succeed " )
472+
473+ // Wait for cleanup to complete
474+ try await Task . sleep ( for: . seconds( 2 ) )
475+
476+ // Verify container was removed
477+ let ( lsOutput, _, _) = try run ( arguments: [ " ls " , " -a " ] )
478+ let containers = lsOutput. components ( separatedBy: . newlines)
479+ . filter { $0. contains ( containerName) }
480+ #expect( containers. isEmpty, " container should be removed with --rm " )
481+
482+ // Verify all 5 anon volumes were cleaned up
483+ let afterCount = try getAnonymousVolumeNames ( ) . count
484+ #expect( afterCount == beforeCount, " all 5 anonymous volumes should be auto-cleaned up with --rm " )
477485 }
478486}
0 commit comments