Test orphan detection with dead PIDs.
()
| 85 | |
| 86 | |
| 87 | def test_orphan_detection(): |
| 88 | """Test orphan detection with dead PIDs.""" |
| 89 | print("Testing orphan detection...") |
| 90 | |
| 91 | with tempfile.TemporaryDirectory() as tmpdir: |
| 92 | db_path = Path(tmpdir) / "test.db" |
| 93 | db = ContainerDatabase(db_path) |
| 94 | |
| 95 | # Insert a record with a dead PID (99999 is unlikely to exist) |
| 96 | dead_pid = 99999 |
| 97 | container_id = "orphan_container_456" |
| 98 | container_name = "orphan-container" |
| 99 | image_name = "test-image:latest" |
| 100 | |
| 101 | db.insert(container_id, container_name, image_name, dead_pid) |
| 102 | |
| 103 | # Verify process_exists returns False for dead PID |
| 104 | assert not process_exists(dead_pid), "Dead PID incorrectly detected as alive" |
| 105 | |
| 106 | # Get all records - should include our orphan |
| 107 | all_records = db.get_all() |
| 108 | assert len(all_records) == 1, "Expected 1 record" |
| 109 | assert all_records[0].owner_pid == dead_pid |
| 110 | |
| 111 | # Note: We can't test actual cleanup_orphaned_containers here because |
| 112 | # it tries to interact with Docker. Just verify the logic detects orphans. |
| 113 | |
| 114 | print("✓ Orphan detection test passed") |
| 115 | |
| 116 | |
| 117 | def test_process_exists(): |
no test coverage detected