@@ -355,7 +355,7 @@ extension IntegrationSuite {
355355 let id = " test-fsnotify-events "
356356
357357 let bs = try await bootstrap ( reference: " docker.io/library/node:18-alpine " )
358- let directory = try createFSNotifyTestDirectory ( )
358+ let directory = try createMountDirectory ( )
359359 let inotifyBuffer : IntegrationSuite . BufferWriter = BufferWriter ( )
360360 let container = try LinuxContainer ( id, rootfs: bs. rootfs, vmm: bs. vmm) { config in
361361 config. process. arguments = [
@@ -378,46 +378,27 @@ extension IntegrationSuite {
378378 let agent = Vminitd ( connection: connection, group: group)
379379 try await Task . sleep ( for: . seconds( 1 ) )
380380
381- // Test 1: CREATE event on existing file
382- print ( " Sending CREATE event... " )
383381 let createResponse = try await agent. notifyFileSystemEvent (
384- path: " /mnt/existing .txt " ,
382+ path: " /mnt/hi .txt " ,
385383 eventType: . create,
386384 containerID: id
387385 )
388386
389387 guard createResponse. success else {
390388 throw IntegrationError . assert ( msg: " CREATE event failed: \( createResponse. error) " )
391389 }
392- print ( " CREATE event succeeded " )
393390
394- // Test 2: MODIFY event on existing file
395- print ( " Sending MODIFY event... " )
396391 let modifyResponse = try await agent. notifyFileSystemEvent (
397- path: " /mnt/existing .txt " ,
392+ path: " /mnt/hi .txt " ,
398393 eventType: . modify,
399394 containerID: id
400395 )
401396 guard modifyResponse. success else {
402397 throw IntegrationError . assert ( msg: " MODIFY event failed: \( modifyResponse. error) " )
403398 }
404- print ( " MODIFY event succeeded " )
405399
406- // Wait for events to be processed
407- print ( " Waiting for inotify events to be detected... " )
408400 try await Task . sleep ( for: . seconds( 1 ) )
409401
410- let inotifyOutput = String ( data: inotifyBuffer. data, encoding: . utf8) ?? " "
411- print ( " === Final Container Output === " )
412- print ( inotifyOutput)
413- print ( " === End Container Output === " )
414-
415- // Verify that inotify detected the modify event
416- guard inotifyOutput. contains ( " change " ) && inotifyOutput. contains ( " existing.txt " ) else {
417- throw IntegrationError . assert ( msg: " inotify did not detect FSNotify agent events. Output: ' \( inotifyOutput) ' " )
418- }
419-
420- // Test 3: DELETE event on non-existent file
421402 let deleteResponse = try await agent. notifyFileSystemEvent (
422403 path: " /mnt/nonexistent.txt " ,
423404 eventType: . delete,
@@ -427,27 +408,28 @@ extension IntegrationSuite {
427408 throw IntegrationError . assert ( msg: " DELETE event failed: \( deleteResponse. error) " )
428409 }
429410
430- // Clean up
431- try await agent. close ( )
432- try await group. shutdownGracefully ( )
433- try await container. stop ( )
411+ try await Task . sleep ( for: . seconds( 1 ) )
434412
435- print ( " All FSNotify events tested successfully " )
436- }
413+ let inotifyOutput = String ( data: inotifyBuffer. data, encoding: . utf8) ?? " "
437414
438- private func createFSNotifyTestDirectory ( ) throws -> URL {
439- let dir = FileManager . default . uniqueTemporaryDirectory ( create : true )
415+ let expectedLines = [ " change hi.txt " , " change hi.txt " ]
416+ let actualLines = inotifyOutput . trimmingCharacters ( in : . whitespacesAndNewlines ) . components ( separatedBy : . newlines ) . filter { !$0 . isEmpty }
440417
441- // Create some test files and directories
442- try " initial content " . write ( to : dir . appendingPathComponent ( " existing.txt " ) , atomically : true , encoding : . utf8 )
443- try " hello world " . write ( to : dir . appendingPathComponent ( " hello.txt " ) , atomically : true , encoding : . utf8 )
418+ guard actualLines . count >= expectedLines . count else {
419+ throw IntegrationError . assert ( msg : " Expected at least \( expectedLines . count ) events, got \( actualLines . count ) . Output: ' \( inotifyOutput ) ' " )
420+ }
444421
445- // Create a subdirectory
446- let subdir = dir. appendingPathComponent ( " subdir " )
447- try FileManager . default. createDirectory ( at: subdir, withIntermediateDirectories: true )
448- try " nested file " . write ( to: subdir. appendingPathComponent ( " nested.txt " ) , atomically: true , encoding: . utf8)
422+ let hasExpectedEvents = expectedLines. allSatisfy { expectedLine in
423+ actualLines. contains ( expectedLine)
424+ }
449425
450- return dir
426+ guard hasExpectedEvents else {
427+ throw IntegrationError . assert ( msg: " Expected events not found. Expected: \( expectedLines) , Actual: \( actualLines) " )
428+ }
429+
430+ try await agent. close ( )
431+ try await group. shutdownGracefully ( )
432+ try await container. stop ( )
451433 }
452434
453435 private func createMountDirectory( ) throws -> URL {
0 commit comments